17

I just recently upgraded to 1.0.3, and the routes.rb file in my config/routes folder seems to ignore all my custom routes.

MY routes.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

If I run bundle exec rake routes, it returns all the approriate routes. But when I try to reach that specific page, I get :

undefined local variable or method `about_us_path'

Or the same error for every link that is within my custom routes. Somehow my routes are being ignored. Does anyone know a way to circumvent this issue?

Trip
  • 26,756
  • 46
  • 158
  • 277

3 Answers3

39

I encountered the same error and found this solution, which solved it by prefixing main_app, before each of my_paths/_urls. In my case, these were links used in one of the /override.rb files.

So, try: main_app.about_us_path.

Outside_Box
  • 447
  • 1
  • 4
  • 16
manafire
  • 5,984
  • 4
  • 43
  • 53
20

You can add new routes in the Spree using following block in routes.rb file

Spree::Core::Engine.routes.prepend do
  # Your new routes
end
  • I found that using `main_app.my_route_path` broke all spree routes unless they were prepended with `spree.`. This solution prevents the need to do that. – Zubin May 15 '13 at 00:54
  • @Zubin Yes, main_app.my_route_path works for accessing main application routes from Spree related controllers/views. For adding a routes to spree, you can use the solution given by me. – Shailesh Kalamkar Jul 24 '13 at 06:59
  • 3
    It seems that prepend method doesn't work any more. Take a look at @Ajay answer – Tania R Jun 22 '15 at 15:07
8

For me prepend did not work. for me draw did the work:

Spree::Core::Engine.routes.draw do
   resources :orders, except: [:new, :create, :destroy] do
      post :my_order, on: :collection
   end
end
Ajay
  • 4,199
  • 4
  • 27
  • 47