Here a code I'm using now.
<%= f.select :project_id, @project_select %>
How to modify it to make it it's default value params[:pid]
when page is loaded?
Here a code I'm using now.
<%= f.select :project_id, @project_select %>
How to modify it to make it it's default value params[:pid]
when page is loaded?
This should work for you. It just passes {:value => params[:pid] }
to the html_options variable.
<%= f.select :project_id, @project_select, {}, {:value => params[:pid] } %>
I've found solution and fount that I'm pretty unexperienced in RoR.
# in controller which manages view described above
@work.project_id = params[:pid] unless params[:pid].nil?
This should do it.
<%= f.select :project_id, @project_select, :selected => params[:pid] %>
if params[:pid] is a string, which if it came from a form, it is, you'll probably need to use
params[:pid].to_i
for the correct item to be selected in the select list
Use the right attribute of the current instance (e.g. @work.project_id
):
<%= f.select :project_id, options_for_select(..., @work.project_id ) %>