Concatenate first_name & last_name in select

Hey,

I want to populate a select drop down form helper with FIRST NAME + LAST
NAME.

However, these are both in separate columns in the DB - how can I join
them together?

I can manage to populate it with just the first names, like this…

===VIEW====

<%= select(:first_name, :id, @guests) %>

===CONTROLLER===

@guests = Guest.find(:all, :conditions => ["group_id = ? and

event_id = ?", params[:id], params[:event]]).map { |u| [u.first_name, u.id]}

Any ideas?

Thanks

On Nov 24, 2007, at 9:28 AM, Scott H. wrote:

Any ideas?

Thanks

I’d suggest getting that stuff out of the controller and into the model:

==Model==

class Guest
def self.choices_for_name_by_group_and_event(group_id, event_id)
find(:all, :conditions => [‘group_id = ? AND event_id = ?’,
group_id, event_id]).
map {|u| [u.name, u.id] }
end
def name
“#{first_name} #{last_name}”
end
end

==Controller==

@guests = Guest.choices_for_name_by_group_and_event(params[:group_id],
params[:event_id])

==View==

 <%= select(:object, :method, @guests) %>

(your select call doesn’t make sense unless you have a variable
@first_name)

That should help you make some sense of it. The biggest help is
having the logic in the model.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]