[英]Adding Routes to Rails' Spree E-Commerce
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.我最近刚升级到1.0.3
,我的 config/routes 文件夹中的 routes.rb 文件似乎忽略了我所有的自定义路由。
MY 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
If I run bundle exec rake routes
, it returns all the approriate routes.如果我运行bundle exec rake 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?有谁知道规避这个问题的方法?
I encountered the same error and found this solution , which solved it by prefixing main_app
, before each of my_paths/_urls
.我遇到了同样的错误并找到了这个解决方案,它通过在每个my_paths/_urls
之前加上前缀main_app
来解决它。 In my case, these were links used in one of the /override.rb
files.在我的例子中,这些是在其中一个/override.rb
文件中使用的链接。
So, try: main_app.about_us_path
.所以,试试: main_app.about_us_path
。
You can add new routes in the Spree using following block in routes.rb file您可以使用 routes.rb 文件中的以下块在 Spree 中添加新路线
Spree::Core::Engine.routes.prepend do
# Your new routes
end
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.