I have a form with one input field — a textarea — and when the user submits the form I want to save the value of the textarea to the session. How do I do that, in Rails?
I’m using Devise, and the page I’m sending the user to after they submit the form is my Devise registration page.
So I imagine I need something like this in the registrations controller action:
session[:text_entered] = params()
…but Devise doesn’t give me a registrations controller. Do I need to make one?
Am I stuck with a super long URL when the form gets submitted? Should this be a POST or a GET? How do I pass the textarea value to the registrations page without sending it as a URL parameter?
Sorry I’m a newbie. Thanks for any help!
So, you have a controller for the page that the textarea is on, let’s call it “SomethingsController.” And the controller the form on that page submits to is, I gather, RegistrationsController. Instead of handling the submission of that form in RegistrationsController, what I would do is let SomethingsController handle it.
When you
POSTthe form to SomethingsController (and yes, you should POST) it will fire thecreateaction, and there you’ll get the value fromparams(which is a Hash–you access its values with[]) and put it insession. Once you’ve done that you can redirect the user to the registration page. Something like this: