0

我正在尝试通过和编辑页面更新我的条带订阅,但它似乎不喜欢我扔给它的任何东西。

这是我的路线.rb

get 'subscribe' => 'subscribe#stepone'
  get 'subscribe/sliding-scale' => 'subscribe#steptwo'
  get 'subscribe/sliding-scale/subscriber' => 'subscribe#subscriber'
  get 'subscribe/sliding-scale/supporter' => 'subscribe#supporter'
  get 'subscribe/sliding-scale/sustainer' => 'subscribe#sustainer'
  post 'subscribe/sliding-scale/:type' => 'subscribe#createSubscription'
  get 'subscribe/edit' => 'subscribe#edit', :as => :edit_subscription
  match '/subscribe/edit', to: 'subscribe#deleteCard', via: :delete
  match '/subscribe/edit', to: 'subscribe#updateSubscription', via: :post
  post 'subscribe/edit/changeSubscription' => 'subscribe#changeSubscription', :as => :change_subscription

我的订阅控制器:

def changeSubscription
    customer = Stripe::Customer.retrieve(@user.stripeCustomerId)
    @plan = params[:plan]
    @user.update_subscription(:plan => @plan, :prorate => true)
    current_role = @user.roles.first.name
    @user.remove_role current_role
    current_user.add_role params[@plan]
  end

最后是我的编辑视图:

 <h2>Change My Subscription</h2>
  <h3>Your current plan is: <%= current_user.roles.first.name %>
  <%= select_tag @plan, options_for_select([['Subscriber'], ['Sustainer'], ['Supporter']]) %>
  <%= link_to "Update", change_subscription_path, :confirm => "You sure?", :plan => @plan %>

我正在尝试将新计划发送到控制器以更新本地角色和计划,但似乎无法找到正确的路径来执行此操作。不知道我在这方面做错了什么。

谢谢你的帮助!

4

1 回答 1

1

您需要对 执行POST请求 change_subscription_path,但您使用简单的 link_to 请求页面,因此它是一个GET请求。

添加:method => :post您的link_to选项:

<%= link_to "Update", change_subscription_path, :confirm => "You sure?", :method => :post, :plan => @plan %>

或者,您可以:

  • 使用表单而不是链接并使用POST方法提交

  • 在 routes.rb 中将changeSubscription操作的方法从更改POSTGET

于 2014-02-10T19:30:53.180 回答