1

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?

4

1 回答 1

4

为每个计划构建链接,使其在 URL 中包含一个参数。

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

这将创建一个类似于http://example.com/signup?plan=pro.

然后,在您的注册页面中,您可以使用以下内容自动将下拉菜单的值设置为 URL 中传递的值:

<%= f.select :plan, @plans, :selected => params[:plan] %>
于 2013-07-23T13:55:29.570 回答