Rails: How to read the value entered by the user in a text_field_tag input?
I have a form with <%= text_field_tag "mykey" %>
. The user enters myvalue
and submits. How to get this value when the POST request hits the Rails server?
I can see myvalue
passing in the POST request:
Started POST "/assessments" for 127.0.0.1 at 2011-07-08 20:04:41 +0900
Processing by AssessmentsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "mykey"=>"myvalue"}
But how can I read this value in my controller?
InAssessmentsController#create
, first thing I do is log the params, and it is unfortunately empty:
logger.debug session[:assessment_params].collect {|k,v| "#{k}: #{v}"}.join
Note: I can not use text_field instead of text_field_tag, 开发者_如何学编程because of another issue.
If your form isn't a model form, which appears to be the case, you just want params[:mykey]
.
精彩评论