Nicolas Raoul
Nicolas Raoul

Reputation: 60213

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?
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.

Upvotes: 1

Views: 2527

Answers (1)

Chowlett
Chowlett

Reputation: 46675

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

Upvotes: 4

Related Questions