简体   繁体   中英

Can't retrieve params from rails form

I've got this form tag from which I want to retrieve a starting date and end date (dd/mm/yy):

<%= form_with(url: "dashboard/index", method: "get") do %>
  <%= date_select :start_date, :date_att %>
  <%= date_select :end_date, :date_att %>
  <%= submit_tag("Apply") %>
<% end %>

This is what I'm doing in my controller once the 'Apply' button has been pushed:

start_f = params[:start_date]

which I expect to give me {"date_att(1i)"=>"2019", "date_att(2i)"=>"10", "date_att(3i)"=>"31"} but instead I get <ActionController::Parameters {"date_att(1i)"=>"2019", "date_att(2i)"=>"10", "date_att(3i)"=>"31"} permitted: false>

I tried looking for ways to make the permitted attribute TRUE but I don't understand.

Can anyone help me on this one? Cheers.

You need to use strong parameters , sth like:

start_f = params.permit(:start_date)[:start_date]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM