“未定义的方法‘companys_path’"错误 [英] "undefined method `companies_path'" error
本文介绍了“未定义的方法‘companys_path’"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我访问company/new"时,出现以下错误:
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| %>
但是当我访问company/1/edit"(使用相同的表单)时,一切正常.这是新建"和编辑"的公司控制器:
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
这是(部分)表格:
<%= form_for(@company) do |f| %>
<!-- Show errors -->
<%= render('layouts/form_errors', :object => @company) %>
我真的不明白错误信息,因为代码中没有使用companies_path"?
I really don't understand the error message, because 'companies_path' is not being used in the code?
更新:这里是 routes.rb:
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'
这是公司模型:
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
结束
推荐答案
你应该改变
resources :company
到
resources :companies
这篇关于“未定义的方法‘companys_path’"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文