John
John

Reputation: 6622

"undefined method `companies_path'" error

when I visit 'company/new', then I get the following error:

undefined method `companies_path'
Extracted source (around line #1):
1: <%= form_for(@company) do |f| %>

But when I visit 'company/1/edit' (which uses the same form) everything works fine. This is the company controller for 'new' and 'edit':

def new
  @company = Company.new
end
def edit
  @company = Company.find(params[:id])
end

And this is (part of) the form:

<%= form_for(@company) do |f| %>
<!-- Show errors -->
<%= render('layouts/form_errors', :object => @company) %>

I really don't understand the error message, because 'companies_path' is not being used in the code?

Update: here is the routes.rb:

  get "users_dashboard/show"
  get "login" => "sessions#new", :as => "login" 
  get "logout" => "sessions#destroy", :as => "logout"

  resources :company
  resources :relations
  resources :activities
  resources :contacts
  resources :notes
  resources :tasks
  resources :users
  resources :sessions

  get "site/index"
  get "site/features"
  get "site/dashboard"

  root :to => 'users_dashboard#show'

And here is the company model:

class Company < ActiveRecord::Base
has_many :users
has_many :relations
has_many :contacts, :through => :relations
has_many :notes, :through => :contacts
has_many :tasks, :through => :contacts
has_one :subscription

accepts_nested_attributes_for :subscription

attr_accessible :name, :address1, :address2, :zipcode, :city, :country, :email,      :website, :telephone, :twitter, :linkedin, :code

validates       :name, :address1, :zipcode, :city, :country, :code, presence: true
validates_length_of :code, :maximum => 3

end

Upvotes: 0

Views: 626

Answers (1)

lucapette
lucapette

Reputation: 20724

You should change

resources :company

to

resources :companies

Upvotes: 2

Related Questions