Ruby on rails Rails控制器操作重定向到刷新页面

Ruby on rails Rails控制器操作重定向到刷新页面,ruby-on-rails,redirect,controller,action,Ruby On Rails,Redirect,Controller,Action,我希望我的页面在记录创建后刷新,此时它会将其指向之前的页面。以下是我的控制器的代码: def create @license = License.new(params[:license]) respond_to do |format| if @license.save format.html { redirect_to :controller => 'customers', :action => 'index' } format.json { render js

我希望我的页面在记录创建后刷新,此时它会将其指向之前的页面。以下是我的控制器的代码:

def create
@license = License.new(params[:license])

respond_to do |format|
  if @license.save
    format.html { redirect_to :controller => 'customers', :action => 'index' }
    format.json { render json: @customer, status: :created, location: @customer }
  else
    format.html { render action: "new" }
    format.json { render json: @customer.errors, status: :unprocessable_entity }
  end

end
如果它说
redirect\u to
,我需要用当前id刷新或链接到当前页面,当前id是
:controller=>“customers”,:action=>“show”
,但要用当前页面记录的id

试试看

redirect_to customer_path(@license.id)
相反

根据routes.rb文件的内容,它应该可以工作

但如果没有,请尝试:

redirect_to show_customer_path(@license.id)
但是,这里我不得不假设,您的客户_controller.rb以某种方式显示了许可证模型中的记录。如果许可证和客户是不同的型号,则必须以其他方式查找客户id

也许是:

redirect_to customer_path(@license.customer_id)
如果许可证未以任何方式连接到客户,您需要将其作为post请求的一部分传入。

请尝试, 我认为您正在将customer_id传递给on params(被许可方属于customer),如果是这样的话
重定向到客户路径(@license.customer)
重定向到客户路径(params[:customer\u id])
重定向到客户路径(@license.customer\u id)
完成了工作:)谢谢!