How to display all values checked in a checkbox using Rails? -
<form action="/decide_start_session" method="get"> <input type="checkbox" name = "subject" value = "netpresentvalue" checked> net present value <input type="checkbox" name = "subject" value = "famafrench" checked> fama french <%= submit_tag("start session", class: "btn btn-success") %> </form> puts params[:subject]
i have first part in view , second line in controller in rails app. if user selects both checkboxes, rails console returns last item checked instead of of them together. idea on how can fix (show checkboxes in console)?
if change name attribute of checkboxes subject[]
, remove spaces around =
in html, checked values passed controller array.
<form action="/decide_start_session" method="get"> <input type="checkbox" name="subject[]" value="netpresentvalue" checked> net present value <input type="checkbox" name="subject[]" value="famafrench" checked> fama french </form>
then can in controller:
puts params[:subject].inspect
Comments
Post a Comment