0

我是 ruby​​ on rails 的新手。我正在尝试在 ruby​​ on rails 上设计一个具有单选按钮BasicPaid用户的注册表单。当用户点击付费并点击提交时,应该会发生以下情况:1)重定向到 PayPal 进行付款。2) 付款确认后将用户保存到 DB(postGres)。

对于基本用户,应创建用户。目前我已经成功创建并测试了 Basic 的场景。这是我的 new.html.erb

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
  <div class="span6 offset3">
    <%= form_for(@user) do |f| %>
      <%= render 'shared/error_messages' %>

      <%= f.label :name %>
      <%= f.text_field :name %>

      <%= f.label :email %>
      <%= f.text_field :email %>

      <%= f.label :password %>
      <%= f.password_field :password %>

      <%= f.label :password_confirmation, "Confirmation" %>
      <%= f.password_field :password_confirmation %>

      <label for="theme">User Type:</label>
      <% [ 'Basic', 'Paid' ].each do |theme| %>
        <%= radio_button_tag 'theme', theme, @theme == theme %>
        <%= theme.humanize %>
      <% end %>
<br/>
<br/>
      <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
    <% end %>
  </div>
</div>

这是我的控制器代码。

    def create
        @user = User.new(params[:user])
        if @user.save
                    sign_in @user
            flash[:success] = "Welcome to Product Recall!"
            redirect_to @user
            else
            render 'new'
        end
    end

请让我知道实施付费方案的最佳方式是什么?提前致谢

4

1 回答 1

1

您可以在创建操作中执行此操作:

def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      if params[:theme] == 'Paid'
        redirect_to paypal_payment_path #This could be your another action in your controller where you may need to initiate something and redirect to paypal 
        return 
      else
        flash[:success] = "Welcome to Product Recall!"
        redirect_to @user
      end
    else
      render 'new'
    end
end
于 2013-06-18T09:25:48.910 回答