17

我刚刚升级到1.0.3,并且我的 config/routes 文件夹中的 routes.rb 文件似乎忽略了我所有的自定义路由。

我的路线.rb

JollyStore::Application.routes.draw do
  # Mount Spree's routes
  mount Spree::Core::Engine, :at => '/'

  root :to => 'pages#index'

  namespace :admin do
    resources :wysiwygs
  end

  match 'about_us/', :to => "pages#about_us"
  match 'services/', :to => "pages#services"
  match 'raw_resources/', :to => "pages#raw_resources"
  match 'contact_us/', :to => "pages#contact_us"

  match 'privacy_policy/', :to => "pages#privacy_policy"
  match 'return_policy/', :to => "pages#return_policy"
  match 'refund_policy/', :to => "pages#refund_policy"
  match 'cancellation_policy/', :to => "pages#cancellation_policy"
  match 'delivery_shipping_policy/', :to => "pages#delivery_shipping_policy"


end

如果我运行bundle exec rake routes,它会返回所有适当的路线。但是当我尝试访问该特定页面时,我得到:

undefined local variable or method `about_us_path'

或者我的自定义路由中的每个链接都出现相同的错误。不知何故,我的路线被忽略了。有谁知道绕过这个问题的方法?

4

3 回答 3

39

我遇到了同样的错误并找到了这个解决方案,它通过main_app在每个my_paths/_urls. 就我而言,这些是其中一个/override.rb文件中使用的链接。

所以,试试:main_app.about_us_path

于 2012-04-18T18:26:40.820 回答
20

您可以使用 routes.rb 文件中的以下块在 Spree 中添加新路线

Spree::Core::Engine.routes.prepend do
  # Your new routes
end
于 2012-08-09T12:44:42.240 回答
8

对我来说,前置没有用。对我来说 draw 做了工作:

Spree::Core::Engine.routes.draw do
   resources :orders, except: [:new, :create, :destroy] do
      post :my_order, on: :collection
   end
end
于 2014-04-05T19:59:37.633 回答