从方法控制器重定向到特定视图
我有一个名为“products_controllers.rb”的控制器,它具有以下方法:
def create
...
...
respond_to do |format|
if @product.save
???????
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
每当保存产品时,我想将其重定向到属于产品视图的名为“suppliers”的特定视图,我该怎么做? 提前致谢!
I have a controller called "products_controllers.rb" that have this method:
def create
...
...
respond_to do |format|
if @product.save
???????
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
Whenever the product is save I want to redirect it to an specific view called "suppliers", that belongs to the product views, how can I do that?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是restful 路线,并且产品有许多供应商,您可以使用:
在您的routes.rb: 中使用类似的内容,
或者您也可以使用以下内容:
If you're using restful routes and there is a relationship where product has many suppliers, you could use:
with something like this in your routes.rb:
or you could also just use this:
像这样的东西
redirect_to '产品/供应商'
来源:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-redirect_to
评论:下次请确保在问题文本中指定“in Rails”,因为许多框架都使用视图和控制器。
Something like
redirect_to 'product/suppliers'
Source:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-redirect_to
Comment: Next time make sure to specify "in rails" in the text of your question since views and controllers are used by many frameworks.
在你的控制器中:
在routes.rb中
In your controller:
In routes.rb