In fact, these are not rails giving you an error, this is a ruby. You are trying to combine the characters :user_firstname and :user_lastname
A symbol is a variable type, as an integer, string or datetime (well, technically they are classes, but in this context we can consider them as variable types). They look like strings and can function similarly to them, but there is no definition of character concatenation behavior. Essentially, you are trying to send the user_firstnameuser_lastname method, which is as insensitive as trying to concatenate two characters.
What you need to understand is that this parameter is looking for a method for your User object, and it will not understand the combination of two characters. You need to define a method in your model:
def fullname [user_firstname, user_lastname].reject{|v| v.blank?}.join(" ") end
This will return your first + name for you, and then in the parameter you should send :fullname (because the method that it will call for each user object in the collection):
<%= collection_select(:user, :user_id, @users, :user_id, :fullname, {:prompt => false})%>
In addition, he believed that it was bad practice to prefix each column with the table name. user.user_firstname just looks redundant. I prefer to refuse this prefix, but I assume that it mainly depends on personal preferences.
source share