Error when trying to use full name as my label method for form dropdown

Posted by Jake Pople

over 1 year ago

0

form label rails

Error message:

undefined method `first_name last_name' for #<User:0x00007fe722d3eaa8>


Create the full name method in your model as shown below

  def full_name
    "#{first_name} #{last_name}"
  end
Then call that method in your label_method

<%= simple_form_for @model_name do |f| %>
  <%= f.association :user, collection: @users, label_method: :full_name %>
<% end %>