I'm trying to get a value from a select box in order to pass the value to the controller but after many attempts I end up with no solution.
Im have this:
<div class="field">
<%= f.label :activityType %><br>
<%= select_tag(:activityType, options_for_select([
["Cycling", "Cycling"],
["Running", "Running"],
["Swimming", "Swimming"],
["Gymn", "Gymn"]
])) %>
</div>
What I'm I doing wrong? In the documentation they do the same ..
The problem is that my validation for presence = true say that the field is blank.
Thank you
You're using
f.label
so probably you also would like to usef.select
insteadselect_tag
. The main difference between them is thatgives exactly
activityType
param name, so it's accessible in controller viaparams[:activityType]
, whereas:gives
params[:object_name][:activityType]
. So that, if you're creating an object viaparams[:object_name]
,activityType
is empty.Note I'm using
:object_name
because I don't know your form object name.