Rails:在表单提交后访问视图中的参数
在我的Rails 3.2项目中,我有一个表单在app/views/sites/
中的new.html.erb
中创建一个新站点
...
...
然后是sites_controller.rb
的create
函数
def create @site = Site.new(params[:site]) respond_to do |format| if @site.save format.html { redirect_to @site } else format.html { render action: "new" } end end end
然后在用户提交后,我想在hash_name
中显示用户刚刚提交的show.html.erb
You just put in .
但访问params[:hash_name]
不起作用。 我该如何访问它?
您将重定向到其他操作 – 这将重置您传递给create操作的所有参数。
将hash_name
作为参数传递,就像其他答案建议的那样,或者直接从@site
对象获取它。
只需将它们附加到选项:
redirect_to @site,:hash_name => params [:hash_name]