Keep params after render Ruby on Rails

不问归期 提交于 2019-12-01 16:32:15
Gopal S Rathore

try

render :action => "new", :id => @project.id

if its not works for you, then try alternate way to pass the parameter to your render action.

This can also help you-> Rails 3 Render => New with Parameter

You shouldn't use params[:id] to assign value to this form field. Instead, add this to your #new action in controller:

def new
  @project = Project.new(user_id: params[:id])
end

and then just write this in your form:

<%= f.hidden_field :user_id %>

Because @project was defined in your #new and #create actions and because it already contains a Project instance with a user_id assigned to it, the value would automatically be added to this field.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!