I am trying to implement internationalization as seen in railscasts, and every time I scope my routes file I get the error
No route matches [GET] "/"
or the error
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)>'
Here is my routes.rb file
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
So, why whenever I add the scope “:locale” do end line do I get these errors? It all works fine without. Let me know if you need to see any more code. Thanks guys
Edit
In my application controller I have the following:
private
def default_url_options(options = {})
{locale: I18n.locale}
end
Does this do the same thing as the passing the hash in the routes?
Edit 2
I changed my route to the following as seen in this gist.
https://gist.github.com/2322844
So why is the :id part being added to the get route? like this one
about_us_site GET /sites/:id/about_us(.:format)
shouldn’t it be something like this
about_us_site GET /sites/about_us(.:format)
Also added my entire routes.rb file and the routes it generates for more information.
https://gist.github.com/2322861
Answer for anyone interested:
I changed
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'
to
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
end
Passing in a hash should fix your routes:
Also, you may want to consider creating a
SitesControllerand giving itmembers: