I try to add an administration area to my website. So I added a namespace that contains the controllers "posts" and "category". In the routes.rb file, I added
namespace :admin do
resources :posts , :categories
match '/' => 'posts#index', :via => :get
end
but with the url:
myurl.com/admin
i have error:
No route matches {:controller=>"admin/site", :action=>"home", :locale=>:fr}
It seems that another route is called and overwrites the one I added
but in rake routes i have:
admin GET /admin(.:format) admin/posts#index
Here the complete rake routes:
faq GET (/:locale)/faq(.:format) site#faq {:locale=>/[a-zA-Z]{2}/}
rules GET (/:locale)/rules(.:format) site#rules {:locale=>/[a-zA-Z]{2}/}
advanced_rules GET (/:locale)/advanced_rules(.:format) site#advanced_rules {:locale=>/[a-zA-Z]{2}/}
play_now GET (/:locale)/play_now(.:format) play#play {:locale=>/[a-zA-Z]{2}/}
play GET (/:locale)/play(.:format) site#play {:locale=>/[a-zA-Z]{2}/}
home GET (/:locale)/home(.:format) site#home {:locale=>/[a-zA-Z]{2}/}
GET (/:locale)/qrcode(/:code)(.:format) site#qrcode {:locale=>/[a-zA-Z]{2}/}
forgot_password GET (/:locale)/forgot_password/:id(.:format) passwords#forgot_password {:locale=>/[a-zA-Z]{2}/}
android_redirect GET (/:locale)/android_redirect(.:format) android#index {:locale=>/[a-zA-Z]{2}/}
general_conditions GET (/:locale)/general_conditions(.:format) site#general_conditions {:locale=>/[a-zA-Z]{2}/}
support GET (/:locale)/support(.:format) site#support {:locale=>/[a-zA-Z]{2}/}
GET (/:locale)/invitation(/:source)(.:format) invitation#redirection {:locale=>/[a-zA-Z]{2}/}
release_notes GET (/:locale)/release_notes(.:format) site#release_notes {:locale=>/[a-zA-Z]{2}/}
release_note GET (/:locale)/release_notes/:version(.:format) release_notes#show {:locale=>/[a-zA-Z]{2}/}
root GET /(:locale)(.:format) site#home {:locale=>/[a-zA-Z]{2}/}
admin_posts GET /admin/posts(.:format) admin/posts#index
POST /admin/posts(.:format) admin/posts#create
new_admin_post GET /admin/posts/new(.:format) admin/posts#new
edit_admin_post GET /admin/posts/:id/edit(.:format) admin/posts#edit
admin_post GET /admin/posts/:id(.:format) admin/posts#show
PUT /admin/posts/:id(.:format) admin/posts#update
DELETE /admin/posts/:id(.:format) admin/posts#destroy
admin_categories GET /admin/categories(.:format) admin/categories#index
POST /admin/categories(.:format) admin/categories#create
new_admin_category GET /admin/categories/new(.:format) admin/categories#new
edit_admin_category GET /admin/categories/:id/edit(.:format) admin/categories#edit
admin_category GET /admin/categories/:id(.:format) admin/categories#show
PUT /admin/categories/:id(.:format) admin/categories#update
DELETE /admin/categories/:id(.:format) admin/categories#destroy
admin GET /admin(.:format) admin/posts#index
completed GET /payment_completed(.:format) payment#completed
android GET /android(.:format) hockeyapps#android
login POST /login(.:format) registrations#login
loginfacebook POST /loginfacebook(.:format) registrations#loginfacebook
status GET /status(.:format) registrations#status
logout DELETE /logout(.:format) registrations#logout
geturl POST /geturl/:id/:token(.:format) paypals#geturl
getstatus POST /getstatus/:id/:token(.:format) paypals#getstatus
payment_completed GET /payment_completed(.:format) payment#completed
forgot_password GET /forgot_password/:id(.:format) passwords#forgot_password
send_password POST /send_password(.:format) passwords#send_password
Here the complete file routes.rb:
scope "(:locale)", :constraints => {:locale => /[a-zA-Z]{2}/} do
match '/faq' => 'site#faq', :via => :get
match '/rules' => 'site#rules', :via => :get
match '/advanced_rules' => 'site#advanced_rules', :via => :get
match '/play_now' => 'play#play', :via => :get
match '/play' => 'site#play', :via => :get
match '/home' => 'site#home', :via => :get
match '/qrcode/(:code)' => 'site#qrcode', :via => :get
match '/forgot_password/:id' => 'passwords#forgot_password', :via => :get, :as => "forgot_password"
match '/android_redirect' => 'android#index', :via => :get, :as => "android_redirect"
match '/general_conditions' => "site#general_conditions", :via => :get
match '/support' => "site#support", :via => :get
match '/invitation/(:source)' => 'invitation#redirection', :via => :get
match '/release_notes' => 'site#release_notes', :via => :get, :as => "release_notes"
match '/release_notes/:version' => 'release_notes#show', :via => :get, :as => "release_note"
root :to => 'site#home', :via => :get
end
namespace :admin do
resources :posts , :categories
match '/' => 'posts#index', :via => :get
end
get 'payment_completed' => 'payment#completed', :as => "completed"
get 'android' => 'hockeyapps#android', :as => 'android'
post 'login' => 'registrations#login', :as => 'login'
post 'loginfacebook' => 'registrations#loginfacebook', :as => 'loginfacebook'
get 'status' => 'registrations#status', :as => 'status'
delete 'logout' => 'registrations#logout', :as => 'logout'
post 'geturl/:id/:token' => 'paypals#geturl', :as => 'geturl'
post 'getstatus/:id/:token' => 'paypals#getstatus', :as => 'getstatus'
get 'payment_completed' => 'payment#completed', :as => 'payment_completed'
#scope :protocol => 'https://', :constraints => { :protocol => 'https://' } do
# resources :passwords
#end
get 'forgot_password/:id' => 'passwords#forgot_password', :as => 'forgot_password'
post 'send_password' => 'passwords#send_password', :as => 'send_password'
end
Any idea about the problem ?
thanks
match '/'
is handled by the root :to => ...
and namespaced. So routing tries to call site#home
in module (namespace) admin
.
Try to put the namespace part in front of the root :to
or match '/admin' separately before defining root
Try this
namespace :admin do
resources :posts , :categories
get '', to: 'posts#index', as: '/'
end
scope "(:locale)", :constraints => {:locale => /[a-zA-Z]{2}/} do
...
root :to => 'site#home', :via => :get
...
end
Output of rake routes
admin GET /admin(.:format) admin/posts#index
Tried with get localhost:3000/admin
Started GET "/admin" for 127.0.0.1 at 2013-06-11 17:41:40 +0700
Processing by Admin::PostsController#index as HTML
Rendered admin/posts/index.html.erb within layouts/application (1.0ms)
Completed 200 OK in 1095ms (Views: 1095.1ms | ActiveRecord: 0.0ms)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.