Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 使用“不重定向到index.html.erb”响应__Ruby On Rails 3_Respond With - Fatal编程技术网

Ruby on rails 3 使用“不重定向到index.html.erb”响应_

Ruby on rails 3 使用“不重定向到index.html.erb”响应_,ruby-on-rails-3,respond-with,Ruby On Rails 3,Respond With,我需要回复者回复的帮助,因为当我创建一个新帖子(在本例中)时,它不会重定向到指定的位置。可能是什么?。这是我创建新帖子的代码片段,但是它被重定向到create.html.erb,而不是我指定的index.html.erb def create @post = Post.create(params[:post]) respond_with(@post, :status => :created, :location => posts_url) end 尝试使用“重定

我需要回复者回复的帮助,因为当我创建一个新帖子(在本例中)时,它不会重定向到指定的位置。可能是什么?。这是我创建新帖子的代码片段,但是它被重定向到create.html.erb,而不是我指定的index.html.erb

 def create
    @post = Post.create(params[:post])
    respond_with(@post, :status => :created, :location => posts_url)
 end
尝试使用“重定向到”(从):

如果您对解决方案不满意,我在类似帖子中找到了一个解决方案:

尝试使用“重定向到”(从):

如果您对解决方案不满意,我在类似帖子中找到了一个解决方案:


您不需要提供位置。它会自动为你做

你需要做的就是

respond_with @post

它将设置正确的状态并将您重定向到posts\u url。

您不需要提供位置。它会自动为你做

你需要做的就是

respond_with @post

它将设置正确的状态并将您重定向到posts\u url。

它可以工作,但我使用respond\u with的原因是为了避免指定每种格式。那么,为什么位置属性不起作用呢?。谢谢你的帮助。它很有效,但我使用respond_的原因是为了避免每个格式的规范。那么,为什么位置属性不起作用呢?。谢谢你的帮助。
respond_with @post