Ruby on rails 条带化Rails取消订阅缺少ID

Ruby on rails 条带化Rails取消订阅缺少ID,ruby-on-rails,stripe-payments,Ruby On Rails,Stripe Payments,我想我的路线或控制器有问题。我尝试了很多,但我不知道如何修复此代码。 它在ActionController中说: 没有路由匹配{:action=>“destroy”,:controller=>“payments”, :order_id=>“sub_AzLXhqXdkvY0Z8”}缺少必需的键:[:id] Dashboard show.html.erb <% @services.each do |service| %> <%= link_to service_path(ser

我想我的路线或控制器有问题。我尝试了很多,但我不知道如何修复此代码。
它在ActionController中说:

没有路由匹配{:action=>“destroy”,:controller=>“payments”, :order_id=>“sub_AzLXhqXdkvY0Z8”}缺少必需的键:[:id]

Dashboard 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 %>
PaymentsController.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
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'

对不起,如果我的代码是混乱的,因为命名。我感谢你的努力

问题在此url帮助器中
order\u payment\u路径(service.orders.last.subscription)

这里有两个pass-two参数,因为它是嵌套路径 第一个参数将对应于您的
订单对象
,第二个参数将对应于您的付款对象
类似于此的
order\u payment\u路径(service.orders.last,service.orders.last.subscription)

问题在此url帮助器中
order\u payment\u路径(service.orders.last.subscription)

这里有两个pass-two参数,因为它是嵌套路径 第一个参数将对应于您的
订单对象
,第二个参数将对应于您的付款对象
类似这样的
order\u payment\u路径(service.orders.last,service.orders.last.subscription)

非常感谢。这是有意义的,因为它是嵌套路径!现在我明白了。当我将subscription=Stripe::subscription.retrieve(params[:subscription])更改为subscription=Stripe::subscription.retrieve(params[:id])@WenqingKevinMa时,它与您的方法起到了作用-很高兴帮助您!非常感谢你。这是有意义的,因为它是嵌套路径!现在我明白了。当我将subscription=Stripe::subscription.retrieve(params[:subscription])更改为subscription=Stripe::subscription.retrieve(params[:id])@WenqingKevinMa时,它与您的方法起到了作用-很高兴帮助您!