Rails 3 从 link_to 设置会话变量
我有一个 Rails 应用程序,用户可以在其中浏览表单中的多个视图。用户在每个页面上选择不同的项目,这些项目有助于他们填写的最终表单。
我现在正在使用 query_strings ,它可以工作。如果用户单击浏览器后退按钮,它会记住之前的 query_string 参数。但是,如果用户单击站点中的按钮返回到流程的最后一步,它不会记住查询字符串。查询字符串也会因失败的创建操作而失败,如果该项目不保存,它会在没有 query_string 的情况下重新呈现新操作...
所以我需要跳转到会话和会话变量。我从未对会话做过任何事情,所以这是未知的领域...
因此流程中的第一步是此时主要关注的问题:我正在获取两个类别,用户必须选择一个或另一个。我想将category.id 设置为会话变量,以便稍后我可以使用它来选择其他内容。这最有意义吗?
<%= link_to "Stores/Field", award_cat_path(:location => "store" ), :class => "buttonOrange" %><br>
<%= link_to "Corp/Westmont/Vaughan", award_cat_path(:location => "corp" ), :class => "buttonOrange" %>
这显示了简单的按钮。查询字符串正在设置:location,我需要转换它!。我可以创建一个简单的块来循环访问类别,但如何将category.id 设置为会话变量,然后如何在下一个视图中检索它......
非常感谢您的帮助。
I have a rails app where a user goes through several views winding up at a form. The user selects different items on each page that contribute to the final form that they fill out.
I am using query_strings right now which works. If the user clicks the browser back button it remembers the previous query_string param. but if the user clicks the button in the site back to the last step in the flow it does not remember the query string. The query string thing also fails through a failed create action, if the item does not save it re-renders the new action without the query_string...
So I need to make the jump to Sessions and session variables. I haven't ever done anything with sessions so this is uncharted territory...
So the first step in the flow is the main concern at this point: I am grabbing two categories and the user must select one or the other. I want to set the category.id as a session variable so that then later I can use it to select other things. Does that make the most sense?
<%= link_to "Stores/Field", award_cat_path(:location => "store" ), :class => "buttonOrange" %><br>
<%= link_to "Corp/Westmont/Vaughan", award_cat_path(:location => "corp" ), :class => "buttonOrange" %>
this shows to simple buttons. The query string is being set with :location, I need to convert this!. I can create a simple block to loop through the categories but how do I set the category.id as a session variable, and then how would I retrieve it in my next view...
thanks so much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试像 wicked 这样的多形式 gem,http://railscasts.com/episodes/ 346-wizard-forms-with-wicked
try a multi-form gem like wicked, http://railscasts.com/episodes/346-wizard-forms-with-wicked