2017-07-08 5 views
1

私のルートやコントローラに問題があると思います。私はそんなに試しましたが、このコードを修正する方法を理解できません。
これはActionControllerに言わない:Stripe Railsキャンセルサブスクリプションが見つからないID

Noルートマッチ{:アクション=> "破壊":コントローラ=> "支払い"、 :ORDER_ID => "sub_AzLXhqXdkvY0Z8"}欠落必要なキー:[:ID]

ダッシュボードshow.html.erb

<% @services.each do |service| %> 
    <%= link_to service_path(service), class: "panel-row" do %> 
    <span class="panel-cell panel-highlight"><%= service.title %></span> 
    <span class="panel-cell"><%= service.student.full_name %></span> 

    #ActionController tells me here is my problem 

    <span><%= button_to "Cancel Subscription", 
    order_payment_path(service.orders.last.subscription), 
    :data => { :confirm => "Are you sure?" }, :method => :delete, 
    class: "btn btn-danger" %></span> 

    # 

    <% end %> 
    <% end %> 
<% end %> 

はorder_payment_pathは、コントローラ

を破壊支払いに行きます

dashboard_controller.rb

def show 
    @user = current_user 
    if @user.profile_picture.nil? 
    @user.profile_picture = "default.jpg" 
    end 
    @students = Student.all 
    @orders = Order.all 
    @order = Order.where(state: 'active') # gives me all the active orders 
    @hash = @order.where(customer: @user.customer_id).map do |hash| 
    hash.service #creates an array of service objects 
    end 
    @surveys = Survey.all 

    if @user.admin == true 
    @services = Service.all 
    else 
    @services = @hash 
    end 
end 

PaymentsController.rb

before_action :set_active_order, only: [:destroy] 
def destroy 
    @user = current_user 
    @subscription = Stripe::Subscription.retrieve(params[:subscription]) 
    @subscription.delete 
    @order.destroy 
    respond_to do |format| 
    format.js do 
     redirect_to dashboard_path, notice: "Successfully Deleted" 
    end 
    format.html do 
     redirect_to dashboard_path 
    end 
    end 
end 

private 

def set_active_order 
    @order = Order.where(state: 'active').find(params[:order_id]) 
end 

routes.rbを

devise_for :users 
resources :students 

resources :services do 
    resources :reviews, only: [ :index, :new, :create ] 
end 
resources :reviews, only: [ :show, :edit, :update, :destroy ] 

resources :surveys, only: [ :new, :create, :index, :show, :destroy ] 

resources :users 

resources :orders, only: [:show, :create] do 
    resources :payments, only: [:new, :create, :destroy] 
end 

get 'dashboard' => 'dashboards#show' 

root to: 'pages#home' 

申し訳ありませんが、私のコードがあるため、ネーミングの乱雑である場合。私はあなたの努力に感謝します!

答えて

0

問題は、次のURLヘルパーである ここでは、このorder_payment_path(service.orders.last, service.orders.last.subscription)のようなお支払い対象に 何かを対応させていただきます。最初の引数は、あなたのorder objectと第二に対応するパス をネストされているので、次の2つのパスの二つの引数を持ってorder_payment_path(service.orders.last.subscription)

+0

ありがとうございました。これはネストされたパスから意味があります!今私はそれを参照してください。それは私がサブスクリプション= Stripe :: Subscription.retrieve(params [:subscription])をサブスクリプション= Stripe :: Subscription.retrieve(params [:id])に変更したときにあなたのアプローチで働いた。 –

+0

@WenqingKevinMa - あなたを助けてくれてありがとう! –

関連する問題