respond_with 不重定向到index.html.erb
我需要响应者 respond_with 的帮助,因为当我创建新帖子时(在本例中)它不会重定向到指定的位置。可以是什么?这是我创建新帖子的代码片段,但它被重定向到 create.html.erb 而不是我指定的index.html.erb。
def create
@post = Post.create(params[:post])
respond_with(@post, :status => :created, :location => posts_url)
end
I need help with the responder respond_with, 'cause when I create a new post (in this case) It doesn't redirect to the location specified. What can be?. This is the piece of my code that creates a new post but It's be redirected to create.html.erb and not the index.html.erb that I specified.
def create
@post = Post.create(params[:post])
respond_with(@post, :status => :created, :location => posts_url)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用“redirect_to”(来自 ACIIcasts - Rails 3 中的控制器 ):
如果您对解决方案不满意,我在类似的帖子中找到了解决方法:链接
try to use "redirect_to" (from ACIIcasts - Controllers in Rails 3):
If you are not confortable with the solution i found a workaround in a similar post: link
您不需要提供位置。它会自动为您完成。
您需要做的就是...
它将设置正确的状态并将您重定向到 posts_url。
You don't need to supply location. It will do it automagically for you.
All you need to do is...
It will set the correct status and redirect you to the posts_url.