我想在rails中将一个参数从一个控制器传递给另一个控制器。 这是第一个控制器:
def create
@grouptorepo = Grouptorepo.new(params[:grouptorepo])
if @grouptorepo.save
fileUpdate
redirect_to create_usermailinglist_path, :group_id => @grouptorepo.group_id, :notice => "Group to repo relation created!"
else
render "new"
end
end
这是第二个:
def create
@g = params[:group_id]
@users = Usertogroup.where("group_id = ?", @g).first
@usermailinglist.user_id = @users.user_id
if @usermailinglist.save
redirect_to repositories_path, :notice => "Relation Created!"
else
render "new"
end
end
@g总是零,我不知道为什么。
答案 0 :(得分:1)
create_usermailinglist_path
帮助器存在语法问题:
redirect_to create_usermailinglist_path(:group_id => @grouptorepo.group_id)
另外,如果你想要flash[:notice]
if @grouptorepo.save
fileUpdate
redirect_to(create_usermailinglist_path(:group_id => @grouptorepo.group_id), :notice => "Group to repo relation created!")
else
render "new"
end