user470763
user470763

Reputation:

Pass parameter to devise sign up

I'm using Devise for user registration in my rails app. I have modified the RegistrationsController and sign up views to add Stripe integration. There are several subscription plans a user can select from a select_tag.

On my home page it displays the plans. When the user selects one and it directs them to the sign up page I want to automatically select that plan in the select_tag. I can do that using if/else statements. How do I tell my sign up view what plan the user selected on the home page?

Upvotes: 1

Views: 1744

Answers (1)

James Chevalier
James Chevalier

Reputation: 10874

Build the link for each plan so that it includes a parameter in the URL.

<%= link_to 'Pro', signup_path(:plan => 'pro') %>

That would create a URL that's something like http://example.com/signup?plan=pro.

Then, in your sign up page, you can automatically set the value of the pull down menu to what was passed in the URL by using something like this:

<%= f.select :plan, @plans, :selected => params[:plan] %>

Upvotes: 4

Related Questions