1

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.

Community
  • 1
  • 1
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • just a tip you might call it `assetment[mykey]` so it will be a part f assetment hash or `assetment[mykey][]` if you want no have an array of values – Bohdan Jul 08 '11 at 12:30

1 Answers1

4

If your form isn't a model form, which appears to be the case, you just want params[:mykey].

Chowlett
  • 45,935
  • 20
  • 116
  • 150