Populate Select box w/ data from another model

35 views
Skip to first unread message

jmp...@gmail.com

unread,
May 8, 2013, 10:00:45 PM5/8/13
to plataformate...@googlegroups.com
Example: 
controller = hdlogs, model = hdlog   |  model # 2 = employee
------------------------------------------------------------------------------------------------
Form
------------------------------------------------------------------------------------------------
= simple_form_for @helplog do |f|
   = f.input :tech, collection: [ "Level1", "Level2", "Level3" ]
   = f.input :user, collection: Employee.all(order: 'first_name'), prompt: "Choose a user"
   = f.button :submit
------------------------------------------------------------------------------------------------
I am trying to populate the select box w/ the employee names from the employee model
when user selects the name from the select box (dropdown) the form will be submitted to
the hdlog model. It is probably something so simple but it is driving me nuts... 


Vasiliy Ermolovich

unread,
May 9, 2013, 7:59:14 AM5/9/13
to plataformate...@googlegroups.com
Not sure what are you trying to do here, but if :user is a association
you might want to use `f.association :user` instead of `f.input
:user`. Please tell you more about your helplog model.
> --
> You received this message because you are subscribed to the Google Groups
> "SimpleForm" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to plataformatec-simp...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Blake

unread,
May 15, 2013, 3:50:53 PM5/15/13
to plataformate...@googlegroups.com
Using your examples
<%= simple_form_for(@hdlog) do |f| %>
<%= f.input :employeeid, collection: Employee.all, label_method: :employee_name, value_method: :id, prompt: 'Choose Employee' 
<% end %>
Try something like that
Reply all
Reply to author
Forward
0 new messages