简体   繁体   中英

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?

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] %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM