在我的 rails 项目中,查看时出现以下错误/subscription/new
:
NoMethodError in Subscriptions#new
Showing /redacted/app/views/subscriptions/new.html.erb where line #4 raised:
undefined method `subscriptions_path' for #<#<Class:0x007fd02c8bbb28>:0x007fd0308f7a48>
Extracted source (around line #4):
1: <div class="grid_6">
2: <h1>New Subscription</h1>
3: <p>
4: <%= form_for @subscription, :html => { class: 'form_dark' } do |f| %>
5: <% if @subscription.errors.any? %>
6: <div class="error_messages">
7: <h1><%= pluralize(@subscription.errors.count, "error") %> prohibited this subscription from being saved:</h1>
我的路线文件包含resource :subscription
此内容。
附加代码信息:
用户型号:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
has_one :subscription
end
订阅模式:
class Subscription < ActiveRecord::Base
attr_accessible :status, :stripe_token, :user_id, :last_charge, :stripe_card_token
belongs_to :user
has_many :payments, :dependent => :destroy
belongs_to :plan
attr_accessor :stripe_card_token
end
我的 SubscriptionsController 新方法:
def new
@subscription = User.find(current_user.id).build_subscription
end
任何帮助表示赞赏,谢谢!