Rails 中的重定向格式错误 [英] Format of redirect is wrong in Rails

查看:48
本文介绍了Rails 中的重定向格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在重定向时将 :user_id 发送到我的索引控制器:

I want to send a :user_id to my index controller when it redirects:

format.html { redirect_to @employee_personal, notice: 'Personal was successfully updated.'}

在我的索引控制器中,我必须发送:

In my index controller I have to send:

@user_id = @employee_personal.user_id

变量.

我该如何发送?在我尝试的重定向中:

How can I send this? In the redirect I tried:

format.html { redirect_to @employee_personal(:user_id => @user_id), notice: 'Personal was successfully updated.' }

错了.

format.html { redirect_to :action => :index, :user_id => @user_id  }

是对的.

我怎样才能以这种格式正确地犯错?

How can I make that error right in that format?

推荐答案

尝试:

format.html { redirect_to @employee_personal, user_id: @user_id, notice: 'Personal was successfully updated.'}

此外,您可以使用参数指定路径,如下所示:

Also, you can specify the path with params, something like this:

format.html { redirect_to employee_personal_path(@employee_personal, user_id: @user_id), notice: 'Personal was successfully updated.'}

这篇关于Rails 中的重定向格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆