Ruby on rails 未定义的方法'contacts#u path';狂欢
我正在尝试向基于spree的网站添加联系人表单。以下是我目前遇到的错误:Ruby on rails 未定义的方法'contacts#u path';狂欢,ruby-on-rails,ruby,ruby-on-rails-4,spree,Ruby On Rails,Ruby,Ruby On Rails 4,Spree,我正在尝试向基于spree的网站添加联系人表单。以下是我目前遇到的错误: Showing /Users/louisstephancruz/loosecanon/app/views/spree/contacts/new.html.erb where line #7 raised: undefined method `contacts_path' for #<#<Class:0x007fe8a4703de0>:0x007fe8a4702670> 档案: sourc
Showing /Users/louisstephancruz/loosecanon/app/views/spree/contacts/new.html.erb where line #7 raised:
undefined method `contacts_path' for #<#<Class:0x007fe8a4703de0>:0x007fe8a4702670>
档案:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.0.5'
gem 'sprockets'
gem 'pg'
gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'mail_form'
gem 'simple_form'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :production do
gem 'rails_12factor'
end
gem 'ckeditor', '~> 4.0.6'
gem 'paperclip'
gem 'aws-sdk'
gem 'spree', '2.2.2'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-2-stable'
gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-2-stable'
gem 'spree_fancy', :git => 'git://github.com/spree/spree_fancy.git', :branch => '2-2-stable'
gem 'spree_digital', :git => 'git://github.com/halo/spree_digital.git', :branch => '2-2-stable'
gem 'spree_blogging_spree', github: 'stefansenk/spree-blogging-spree'
gem 'spree_editor', github: 'spree/spree_editor', :branch => '2-2-stable'
gem 'spree_related_products', github: 'spree/spree_related_products', branch: '2-2-stable'
我尝试过将控制器/视图文件移出spree文件夹,还尝试过路由文件中的十几种方法。我错过了什么
编辑
耙道(相关材料):
假设您在商店端执行此操作,您必须执行以下操作:
Spree::Core::Engine.routes.prepend do
resources :contacts, only: [:new, :create]
end
你对狂欢的理解可能和我的不同,不过你知道大致的意思
然后在表格上,您可以执行以下操作:
<%= simple_form_for @contact, :url => contacts_url :html => {:class => 'form-horizontal' } do |f| %>
使用url并查看rake路由,它将解决您的问题
rake routes
对此有何评论?是否列出了它?另外,以防万一,如果您正在使用rails s
实例,您是否重新启动了该实例?我有一些新的路由没有被选中,造成了混乱。你有没有尝试过名称空间:spree do resources:contacts end
?尼克,我会在上面发布rake路由,是的,每次更改我都会重新启动rails服务器。Iceman,我没有尝试过。我应该把它放在哪里?不幸的是,这并没有改变任何事情。再次感谢!你能编辑文章以包含rake routes的输出吗?做了一些编辑,我认为应该可以解决你的问题。嗯,还不行。我尝试了所有这些组合,但运气不好。哦,现在我明白了!当我把“Spree::Core::Engine.routes.append do…”放在我的应用程序路由中时,它起作用了。我甚至不必指向:url。谢谢@railsdevmtl!(当我有足够的声誉时,我一定会投你一票。)
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.0.5'
gem 'sprockets'
gem 'pg'
gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'mail_form'
gem 'simple_form'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :production do
gem 'rails_12factor'
end
gem 'ckeditor', '~> 4.0.6'
gem 'paperclip'
gem 'aws-sdk'
gem 'spree', '2.2.2'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-2-stable'
gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-2-stable'
gem 'spree_fancy', :git => 'git://github.com/spree/spree_fancy.git', :branch => '2-2-stable'
gem 'spree_digital', :git => 'git://github.com/halo/spree_digital.git', :branch => '2-2-stable'
gem 'spree_blogging_spree', github: 'stefansenk/spree-blogging-spree'
gem 'spree_editor', github: 'spree/spree_editor', :branch => '2-2-stable'
gem 'spree_related_products', github: 'spree/spree_related_products', branch: '2-2-stable'
Prefix Verb URI Pattern Controller#Action
spree / Spree::Core::Engine
ckeditor /ckeditor Ckeditor::Engine
about GET /about(.:format) spree/static_pages#about
contacts GET /contacts(.:format) spree/contacts#new
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
Spree::Core::Engine.routes.prepend do
resources :contacts, only: [:new, :create]
end
<%= simple_form_for @contact, :url => contacts_url :html => {:class => 'form-horizontal' } do |f| %>
:url => spree.contacts_url