forms - No params being posted to Rails controller -
i have form in app nested fields. i'm using simple_form_for
, bootstrap, slim , rails 4.2 , form backing object described here
here's proof params missing on server side (n.b. have checked authenticity_token
field in markup)
this log
started post "/example_sentences/9/breakdowns" ::1 @ 2015-08-31 12:37:57 +0900 activerecord::schemamigration load (18.8ms) select "schema_migrations".* "schema_migrations" processing breakdownscontroller#create html parameters: {"example_sentence_id"=>"9"} can't verify csrf token authenticity
switching off csrf protection try , debug gives this:
started post "/example_sentences/9/breakdowns" ::1 @ 2015-08-31 13:00:05 +0900 processing breakdownscontroller#create html parameters: {"example_sentence_id"=>"9"} user load (24.1ms) select "users".* "users" "users"."id" = $1 order "users"."id" asc limit 1 [["id", 1]] completed 400 bad request in 355ms (activerecord: 156.3ms) actioncontroller::parametermissing - param missing or value empty: breakdown:
obviously, there's quite number of factors mean deviating rails way, number of things going wrong. , showing view code introduce lot more questions.
so, i'll show generated html (minus styling info) , ask if can see wrong this. i'm kind of hoping facepalm moment , missing obvious.
<form novalidate="novalidate" id="new_breakdown" action="/example_sentences/9/breakdowns" accept-charset="utf-8" method="post"> <input name="utf8" type="hidden" value="✓"> <input type="hidden" name="authenticity_token" value="cou87ezxrkv1a0qa1ohwlqm5ny43qvgcraqkan9mdgs12jr8rnjfyvxp9vijhkmrkbuvz16io7qagcbazjvqgw=="> <input type="text" value="これ" name="breakdown[word_mapping][1][text]" id="breakdown_word_mapping_1_text" > <input type="text" value="this" name="breakdown[word_mapping][1][translation]" id="breakdown_word_mapping_1_translation"> <input type="text" value="は" name="breakdown[word_mapping][2][text]" id="breakdown_word_mapping_2_text"> <input type="text" value="" name="breakdown[word_mapping][2][translation]" id="breakdown_word_mapping_2_translation"> <input type="submit" name="commit" value="save translations"> </form>
additional info
in ~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_controller/metal/request_forgery_protection.rb
during :valid_authenticity_token?
check line 277
for request.body.read can see authenticity token "utf8=%e2%9c%93&authenticity_token=rtfwcjz3qnrgnnwff66ej2aetx7h5n7bcblkw4v145yadl6ylljb%2beaeznfiok0ivbkvv64sjwkuaybroqb%2fhg%3d%3d&breakdown%5bword_mapping%5d%5b1%5d%5btext%5d=%e3%81%93%e3%82%8c&breakdown%5bword_mapping%5d%5b1%5d%5btranslation%5d=this&breakdown%5bword_mapping%5d%5b1%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b1%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b2%5d%5btext%5d=%e3%81%af&breakdown%5bword_mapping%5d%5b2%5d%5btranslation%5d=&breakdown%5bword_mapping%5d%5b2%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b2%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b3%5d%5btext%5d=%e3%83%9a%e3%83%b3&breakdown%5bword_mapping%5d%5b3%5d%5btranslation%5d=pen&breakdown%5bword_mapping%5d%5b3%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b3%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b4%5d%5btext%5d=%e3%81%a7%e3%81%99&breakdown%5bword_mapping%5d%5b4%5d%5btranslation%5d=&breakdown%5bword_mapping%5d%5b4%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b4%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b%5d%5btext%5d=%e3%81%93%e3%82%8c&breakdown%5bword_mapping%5d%5b%5d%5btranslation%5d=&breakdown%5bword_mapping%5d%5b%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b%5d%5btext%5d=%e3%81%af&breakdown%5bword_mapping%5d%5b%5d%5btranslation%5d=&breakdown%5bword_mapping%5d%5b%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b%5d%5btext%5d=%e3%83%9a%e3%83%b3&breakdown%5bword_mapping%5d%5b%5d%5btranslation%5d=&breakdown%5bword_mapping%5d%5b%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b%5d%5b_destroy%5d=0&breakdown%5bword_mapping%5d%5b%5d%5btext%5d=%e3%81%a7%e3%81%99&breakdown%5bword_mapping%5d%5b%5d%5btranslation%5d=&breakdown%5bword_mapping%5d%5b%5d%5breading%5d=&breakdown%5bword_mapping%5d%5b%5d%5b_destroy%5d=0&commit=save+translations"
but value of encoded_masked_token
nil
in fact path_parameters
part of params i'm getting in request.
in: "~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/http/request.rb" (byebug) pp @env.keys.sort.grep(/action_dispatch/).grep(/param/).map{|k| [k, @env[k]]} [["action_dispatch.parameter_filter", [:password]], ["action_dispatch.request.parameters", {"controller"=>"breakdowns", "action"=>"create", "example_sentence_id"=>"9"}], ["action_dispatch.request.path_parameters", {:controller=>"breakdowns", :action=>"create", :example_sentence_id=>"9"}], ["action_dispatch.request.query_parameters", {}], ["action_dispatch.request.request_parameters", {}]]
so i'm somehow losing params already.
from error message, sounds code require parameters incorrect.
if have following:
params.require(breakdown: [fields])
then should
params.require(:breakdown).permit(fields)
give try.
Comments
Post a Comment