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 单击按钮后重定向到另一个控制器 简单问题:_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 单击按钮后重定向到另一个控制器 简单问题:

Ruby on rails 单击按钮后重定向到另一个控制器 简单问题:,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有一个按钮,每当用户点击这个按钮时,我想将他重定向到另一个控制器中的另一个操作。我怎么能这么做 此代码将位于.html.erb文件中 <%= form.submit "Create Request"%> 注意:我不想使用链接到!此外,我无法在控制器中使用重定向,因为我在那里使用了render 在控制器内的“创建”操作中,保存值后,可以在任何地方重定向。 例如: def create @model = Model.new(permited_params) respon

我有一个按钮,每当用户点击这个按钮时,我想将他重定向到另一个控制器中的另一个操作。我怎么能这么做

此代码将位于
.html.erb
文件中

<%= form.submit "Create Request"%>

注意:我不想使用链接到!此外,我无法在控制器中使用重定向,因为我在那里使用了
render


在控制器内的“创建”操作中,保存值后,可以在任何地方重定向。 例如:

def create
  @model = Model.new(permited_params)

  respond_to do |format|
    If @model.save
      format.html { # todo block with redirect }
    end
  end
end

在表单中使用remote:true,例如:

<% form_tag create_path(params_you_needed), remote: true do |form| %>

为create方法create.js.erb添加rails js

$('#id').html('<%= j render(:partial => "file/location", :locals => {data}) %>');
$('#id').html(''file/location',:locals=>{data})%>');

这样你就可以渲染你需要的文件了

分享您已经完成的工作,包括有问题的控制器代码