Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 4 嵌套表单在销毁后重定向_Ruby On Rails 4_Nested Forms_Nested Attributes - Fatal编程技术网

Ruby on rails 4 嵌套表单在销毁后重定向

Ruby on rails 4 嵌套表单在销毁后重定向,ruby-on-rails-4,nested-forms,nested-attributes,Ruby On Rails 4,Nested Forms,Nested Attributes,当子记录被销毁时,是否有方法重定向回父记录 例如: 在“父项显示”视图中,可以使用嵌套表单创建子项。但是,当通过“销毁”删除子级时,是否可以将用户重定向回正重定向回标准父路径的同一父记录 谢谢 在销毁操作中使用重定向到: # assuming this is a nested resourceful route like: /parents/:parent_id/children/:id def destroy parent = SomeModel.find params[:parent_i

当子记录被销毁时,是否有方法重定向回父记录

例如: 在“父项显示”视图中,可以使用嵌套表单创建子项。但是,当通过“销毁”删除子级时,是否可以将用户重定向回正重定向回标准父路径的同一父记录


谢谢

在销毁操作中使用
重定向到

# assuming this is a nested resourceful route like: /parents/:parent_id/children/:id
def destroy
  parent = SomeModel.find params[:parent_id]
  child = parent.children.find params[:id]
  child.destroy

  redirect_to :back # will redirect back to the referrer (page from where you came from)
end

这实际上是:
重定向到request.referer
,当用户在子模型上单击delete时,它会将用户带到他们所在的页面。

Spot on!我知道这很简单。谢谢