Andrey Drozdov
Andrey Drozdov

Reputation: 591

Rails. Save pass parameter from action to action

For example, user visiting home with invitation link localhost:3000/home?invitation=invitation_token and I want to keep in params while user is browsing site till he visit registration page.

I know there is possibility to add params to link_to method but there is to many where I need to put this and it's not possible to predict user behavior.

But what I'm looking it's custom method what I will place in before_action what will check if there is params[:invitation] and pass it to next, unpredictable, method.

PS. I know that I can save to cookies, but this is not quite what I'm looking for.

Upvotes: 0

Views: 57

Answers (1)

Shannon
Shannon

Reputation: 3018

You should save it in a session variable such as session[:invitation_token], otherwise you'll have to pass the param in every link. You can then use the variable directly such as:

before_action :check_token

def check_token
  redirect_to registration_url unless session[:invitation_token]
end

Upvotes: 2

Related Questions