ruby on rails - Using collection_select or select or select_tag -


(Note: I've read, but still do not know what to take)

I have a form that will be used as search filter (receives method).

  <% = form_tag (reports_courses_allocated_path ,: method = & gt; 'mill')%> & Lt;% = collection_select (: Course ,: ID, @ course,: ID, Title ,: include_blank = & gt; "All Courses")% & gt; & Lt; / Form & gt;   

The above I produce the desired product for the tag, but there is no "selected" parameter where I can pass in the parameter value. I also do not have the fact that the name is absolutely [id], I have to name it course_id I

    

But I do not like the fact that I am adding alternatives together, but this may be my best bet.

Any feedback / suggestions?

Should there be a parameter value to set 'selected' in your case? The 'selected' value for Collection_select is based on the value of @ course.id - you can ensure that the @ course indicates one that should be selected.

For the name, I must stay together while typing my own HTML Rail Default too. This is what determines how the parameters come in your action. If the names of your elements are of course [id], the course [name], the course [type], etc., the parameter will be

  {: course = & gt; {: Id = & gt; Xx ,: name = & gt; Xx ,: type = & gt; Xx}}   

which is convenient because you can call

  course.new (params [: curriculum])   

In addition, you do not need to close your form with your own HTML form tag. The method form_tag takes one block:

  & lt;% = form_tag ('/ posts') -%> & Lt; Div & gt; & Lt;% = submit_tag 'Save'% & gt; & Lt; / Div & gt; & Lt;% end -% & gt;   

And finally ... I have used select_tag and have made an option list before this. It can be ugly, but you can make it in ways in the visual assistant, where it does not clutter your RFLL and where this unit can be tested.

Comments