On Nov 24, 2007, at 9:28 AM, Scott Holland wrote:> 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
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 Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---