我正在尝试实现在 railscasts 中看到的国际化,每次我确定路由文件的范围时,我都会收到错误消息
No route matches [GET] "/"
或错误
missing :controller
config/routes.rb:6:in `block (2 levels) in <top (required)>'
config/routes.rb:5:in `block in <top (required)>'
config/routes.rb:1:in `<top (required)>'
这是我的 routes.rb 文件
Jensenlocksmithing::Application.routes.draw do
get "log_out" => "sessions#destroy", as: "log_out"
get "log_in" => "sessions#new", as: "log_in"
scope ":locale" do
get "site/home"
get "site/about_us"
get "site/faq"
get "site/discounts"
get "site/services"
get "site/contact_us"
get "site/admin"
get "site/posts"
root :to => 'site#home'
end
#match '*path', to: redirect("/#{I18n.default_locale}/%{path}")
#match '', to: redirect("/#{I18n.default_locale}")
match "/savesort" => 'site#savesort'
resources :users
resources :abouts
resources :sessions
resources :coupons
resources :monthly_posts
resources :reviews
resources :categories do
collection { post :sort }
resources :children, :controller => :categories, :only => [:index, :new, :create, :new_subcategory]
end
resources :products do
member do
put :move_up
put :move_down
end
end
resources :faqs do
collection { post :sort }
end
end
那么,为什么每当我添加范围 ":locale" do end line 时都会出现这些错误?没有它一切都很好。如果您需要查看更多代码,请告诉我。多谢你们
编辑
在我的应用程序控制器中,我有以下内容:
private
def default_url_options(options = {})
{locale: I18n.locale}
end
这是否与在路由中传递哈希值相同?
编辑 2
如本要点所示,我将路线更改为以下路线。 https://gist.github.com/2322844
那么为什么 :id 部分被添加到 get 路由中呢?像这个
about_us_site GET /sites/:id/about_us(.:format)
不应该是这样的吗
about_us_site GET /sites/about_us(.:format)
还添加了我的整个 routes.rb 文件及其生成的路由以获取更多信息。
https://gist.github.com/2322861
有兴趣的人回答:
我变了
get "site/home"
get "site/about_us"
get "site/faq"
get "site/discounts"
get "site/services"
get "site/contact_us"
get "site/admin"
get "site/posts"
root :to => 'site#home'
到
resources :sites, except: [:new, :edit, :index, :show, :update, :destroy, :create] do
collection do
get :home
get :about_us
get :faq
get :discounts
get :services
get :contact_us
get :admin
get :posts
end
结尾