Topic: concatinating a string in the a dd

I am trying to get a person full name to show on a dropdown menu but i am not able to do so

 <%= collection_select(:staff_id, :id, @staff, :id, :first_name + " " : last_name , {:prompt => true}) %>

I get a NoMethodError
undefined method `+' for :first_name:Symbol

Re: concatinating a string in the a dd

Just implement a helper method in a corresponding helper class or directly in the model and call in the view:

#model implementation example
def full_name
  first_name + ' '  + last_name
end

In your view:

<%= collection_select(:staff_id, :id, @staff, :id, :full_name, {:prompt => true}) %>

Last edited by Javix (2012-06-19 15:30:27)