Passing arguments from one controller to another in ruby on rails

I want to pass an argument from one controller to another in rails. This is first controller:

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

And this is the second one:

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 is always nil I have no idea why.

Upvotes: 2

Views: 2083

Answers (1)

MrYoshiji
MrYoshiji

Reputation: 54902

You have a syntax problem with the create_usermailinglist_path helper:

redirect_to create_usermailinglist_path(:group_id => @grouptorepo.group_id)

Also, if you want the 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

Upvotes: 1

Related Questions