如何将文本区域值保存到 Rails 会话中?
我有一个带有一个输入字段(文本区域)的表单,当用户提交表单时,我想将文本区域的值保存到会话中。在 Rails 中我该如何做到这一点?
我正在使用 Devise,用户提交表单后我将其发送到的页面是我的 Devise 注册页面。
所以我想我在注册控制器操作中需要类似的东西:
session[:text_entered] = params()
...但是 Devise 没有给我一个注册控制器。我需要做一个吗?
提交表单时,我是否遇到了超长 URL 的问题?这应该是 POST 还是 GET?如何将 textarea 值传递到注册页面而不将其作为 URL 参数发送?
抱歉我是新手。感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您有一个文本区域所在页面的控制器,我们将其称为“SomethingsController”。据我所知,该页面上的表单提交到的控制器是 RegistrationsController。我不会在 RegistrationsController 中处理该表单的提交,而是让 SomethingsController 处理它。
当您将表单
POST
到SomethingsController(是的,您应该POST)时,它将触发create
操作,然后您将从params<获取值/code> (这是一个哈希 - 您可以使用
[]
访问其值)并将其放入session
中。完成后,您可以将用户重定向到注册页面。像这样的东西: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
POST
the form to SomethingsController (and yes, you should POST) it will fire thecreate
action, 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: