1
我想我的路線或我的控制器有問題。我嘗試了太多,但我無法弄清楚如何解決這個問題。
它說,在ActionController的:Stripe Rails取消訂閱丟失ID
沒有路由匹配{:動作=> 「消滅」,:控制器=> 「付款」, :ORDER_ID => 「sub_AzLXhqXdkvY0Z8」}缺少必需的鍵:[:編號]
儀表板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'
很抱歉,如果我的代碼是因爲命名的混亂。我感謝你的努力!
非常感謝。這是有道理的,因爲它是一個嵌套的路徑!現在我明白了。當我將訂閱= Stripe :: Subscription.retrieve(params [:subscription])更改爲subscription = Stripe :: Subscription.retrieve(params [:id]) –
@WenqingKevinMa - 很高興爲您效勞! –