开发者

Rails: How to read the value entered by the user in a text_field_tag input?

开发者 https://www.devze.com 2023-03-19 01:29 出处:网络
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 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?

In AssessmentsController#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].

0

精彩评论

暂无评论...
验证码 换一张
取 消