In my rails project I’m getting the following error when I view /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>
My routes file contains resource :subscription for this.
Additional code information:
User model:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
has_one :subscription
end
Subscription model:
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
My SubscriptionsController new method:
def new
@subscription = User.find(current_user.id).build_subscription
end
Any help is appreciated, thanks!
I believe that when you pass form_for an object like @subscription (which has class Subscription), it expects the url subscriptions_path by default. But since you have declared subscription as a singlular resource, the url subscription_path is defined instead. You should explicitly specify this route