Rails: How to make a custom route from resource - ruby-on-rails

I have an Enki blog set up and the sign in's at www.localhost:3000/admin.`
I'm guessing that this admin url is determined by this code from routes, but, for extra security reasons, I'd like to make the login, for example,
www.localhost:3000/ilovejesus
Enki::Application.routes.draw do
namespace 'admin' do
resource :session
Based on what rake routes is telling me, I'm guessing it's the admin_root that goes to :controller => Admin/Dashboard, :action => 'show' that needs to get changed.
So can anyone tell me how I might change this too, for example, localhost:3000/iloveronpaul
Rake Routes:
admin_session POST /admin/session(.:format) {:action=>"create", :controller=>"admin/sessions"}
new_admin_session GET /admin/session/new(.:format) {:action=>"new", :controller=>"admin/sessions"}
edit_admin_session GET /admin/session/edit(.:format) {:action=>"edit", :controller=>"admin/sessions"}
GET /admin/session(.:format) {:action=>"show", :controller=>"admin/sessions"}
PUT /admin/session(.:format) {:action=>"update", :controller=>"admin/sessions"}
DELETE /admin/session(.:format) {:action=>"destroy", :controller=>"admin/sessions"}
preview_admin_posts POST /admin/posts/preview(.:format) {:action=>"preview", :controller=>"admin/posts"}
admin_posts GET /admin/posts(.:format) {:action=>"index", :controller=>"admin/posts"}
POST /admin/posts(.:format) {:action=>"create", :controller=>"admin/posts"}
new_admin_post GET /admin/posts/new(.:format) {:action=>"new", :controller=>"admin/posts"}
edit_admin_post GET /admin/posts/:id/edit(.:format) {:action=>"edit", :controller=>"admin/posts"}
admin_post GET /admin/posts/:id(.:format) {:action=>"show", :controller=>"admin/posts"}
PUT /admin/posts/:id(.:format) {:action=>"update", :controller=>"admin/posts"}
DELETE /admin/posts/:id(.:format) {:action=>"destroy", :controller=>"admin/posts"}
preview_admin_pages POST /admin/pages/preview(.:format) {:action=>"preview", :controller=>"admin/pages"}
admin_pages GET /admin/pages(.:format) {:action=>"index", :controller=>"admin/pages"}
POST /admin/pages(.:format) {:action=>"create", :controller=>"admin/pages"}
new_admin_page GET /admin/pages/new(.:format) {:action=>"new", :controller=>"admin/pages"}
edit_admin_page GET /admin/pages/:id/edit(.:format) {:action=>"edit", :controller=>"admin/pages"}
admin_page GET /admin/pages/:id(.:format) {:action=>"show", :controller=>"admin/pages"}
PUT /admin/pages/:id(.:format) {:action=>"update", :controller=>"admin/pages"}
DELETE /admin/pages/:id(.:format) {:action=>"destroy", :controller=>"admin/pages"}
admin_comments GET /admin/comments(.:format) {:action=>"index", :controller=>"admin/comments"}
POST /admin/comments(.:format) {:action=>"create", :controller=>"admin/comments"}
new_admin_comment GET /admin/comments/new(.:format) {:action=>"new", :controller=>"admin/comments"}
edit_admin_comment GET /admin/comments/:id/edit(.:format) {:action=>"edit", :controller=>"admin/comments"}
admin_comment GET /admin/comments/:id(.:format) {:action=>"show", :controller=>"admin/comments"}
PUT /admin/comments/:id(.:format) {:action=>"update", :controller=>"admin/comments"}
DELETE /admin/comments/:id(.:format) {:action=>"destroy", :controller=>"admin/comments"}
undo_admin_undo_item POST /admin/undo_items/:id/undo(.:format) {:action=>"undo", :controller=>"admin/undo_items"}
admin_undo_items GET /admin/undo_items(.:format) {:action=>"index", :controller=>"admin/undo_items"}
POST /admin/undo_items(.:format) {:action=>"create", :controller=>"admin/undo_items"}
new_admin_undo_item GET /admin/undo_items/new(.:format) {:action=>"new", :controller=>"admin/undo_items"}
edit_admin_undo_item GET /admin/undo_items/:id/edit(.:format) {:action=>"edit", :controller=>"admin/undo_items"}
admin_undo_item GET /admin/undo_items/:id(.:format) {:action=>"show", :controller=>"admin/undo_items"}
PUT /admin/undo_items/:id(.:format) {:action=>"update", :controller=>"admin/undo_items"}
DELETE /admin/undo_items/:id(.:format) {:action=>"destroy", :controller=>"admin/undo_items"}
admin_health /admin/health(/:action)(.:format) {:action=>"index", :controller=>"admin/health"}
admin_root /admin(.:format) {:controller=>"admin/dashboard", :action=>"show"}
archives GET /archives(.:format) {:action=>"index", :controller=>"archives"}
page GET /pages/:id(.:format) {:action=>"show", :controller=>"pages"}
GET /:year/:month/:day/:slug/comments(.:format) {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"comments", :action=>"index"}
POST /:year/:month/:day/:slug/comments(.:format) {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"comments", :action=>"create"}
GET /:year/:month/:day/:slug/comments/new(.:format) {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"comments", :action=>"new"}
GET /:year/:month/:day/:slug(.:format) {:year=>/\d{4}/, :month=>/\d{2}/, :day=>/\d{2}/, :controller=>"posts", :action=>"show"}
formatted_posts GET /posts.:format {:controller=>"posts", :action=>"index"}
posts GET /(:tag)(.:format) {:controller=>"posts", :action=>"index"}
root /(.:format) {:controller=>"posts", :action=>"index"}

Add a :path option to your namespace
Enki::Application.routes.draw do
scope :module => 'admin' do
resource :session, :path_names => { :new => "liverandonions",
:show => "ilovejesus,
:edit => "iloveronpaul" }
I'm not sure but the path_names options might have to be wrapped in array.
ie.
resource :session, :path_names => { [:new => "liverandonions",
:show => "ilovejesus,
:edit => "iloveronpaul"] }
let me know which one works.

Related

Routing issue with Rails 3

Rails newbie question that I can't seem to figure out. At some point I managed to break routing from one of my resources in my application sitewide. I'm getting the following for every page on my site:
Routing Error
No route matches {:action=>"show", :controller=>"assets", :ext=>"css", :body=>true, :digest=>false, :id=>#}
If I remove the <%= stylesheet_link_tag "application" %> and <%= javascript_include_tag "application" %> everything works correctly.
I have the following in my route.rb file:
resources :security_prices
resources :securities
resources :assets
resources :portfolios do
resources :accounts
end
but when I do a rake routes
I get:
security_prices GET /security_prices(.:format) {:action=>"index", :controller=>"security_prices"}
POST /security_prices(.:format) {:action=>"create", :controller=>"security_prices"}
new_security_price GET /security_prices/new(.:format) {:action=>"new", :controller=>"security_prices"}
edit_security_price GET /security_prices/:id/edit(.:format) {:action=>"edit", :controller=>"security_prices"}
security_price GET /security_prices/:id(.:format) {:action=>"show", :controller=>"security_prices"}
PUT /security_prices/:id(.:format) {:action=>"update", :controller=>"security_prices"}
DELETE /security_prices/:id(.:format) {:action=>"destroy", :controller=>"security_prices"}
securities GET /securities(.:format) {:action=>"index", :controller=>"securities"}
POST /securities(.:format) {:action=>"create", :controller=>"securities"}
new_security GET /securities/new(.:format) {:action=>"new", :controller=>"securities"}
edit_security GET /securities/:id/edit(.:format) {:action=>"edit", :controller=>"securities"}
security GET /securities/:id(.:format) {:action=>"show", :controller=>"securities"}
PUT /securities/:id(.:format) {:action=>"update", :controller=>"securities"}
DELETE /securities/:id(.:format) {:action=>"destroy", :controller=>"securities"}
portfolio_accounts GET /portfolios/:portfolio_id/accounts(.:format) {:action=>"index", :controller=>"accounts"}
POST /portfolios/:portfolio_id/accounts(.:format) {:action=>"create", :controller=>"accounts"}
new_portfolio_account GET /portfolios/:portfolio_id/accounts/new(.:format) {:action=>"new", :controller=>"accounts"}
edit_portfolio_account GET /portfolios/:portfolio_id/accounts/:id/edit(.:format) {:action=>"edit", :controller=>"accounts"}
portfolio_account GET /portfolios/:portfolio_id/accounts/:id(.:format) {:action=>"show", :controller=>"accounts"}
PUT /portfolios/:portfolio_id/accounts/:id(.:format) {:action=>"update", :controller=>"accounts"}
DELETE /portfolios/:portfolio_id/accounts/:id(.:format) {:action=>"destroy", :controller=>"accounts"}
portfolios GET /portfolios(.:format) {:action=>"index", :controller=>"portfolios"}
POST /portfolios(.:format) {:action=>"create", :controller=>"portfolios"}
new_portfolio GET /portfolios/new(.:format) {:action=>"new", :controller=>"portfolios"}
edit_portfolio GET /portfolios/:id/edit(.:format) {:action=>"edit", :controller=>"portfolios"}
portfolio GET /portfolios/:id(.:format) {:action=>"show", :controller=>"portfolios"}
PUT /portfolios/:id(.:format) {:action=>"update", :controller=>"portfolios"}
DELETE /portfolios/:id(.:format) {:action=>"destroy", :controller=>"portfolios"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
which obviously doesn't have assets so I suspect I'm flubbing something. How do I go about debugging this?
remove the resources :assets from the routes.rb rails is doing this on its own you dont need ressources for that!

Rails 3.1 - Devise - CanCan: "../users/sign_out" gets routing error "uninitialized constant UsersController"

"sign_in" works fine but clicking on "sign_out" link locks up during routing (see routes.rb below).
Not sure where to proceed. I'm using RubyMine (IDE) debugger.
I click on a link from layout/applications.html.erb:
<%= link_to('Logout', destroy_user_session_path) %>
RM Debugger watchlist shows: destroy_user_session_path="/user/sign_out"
When I sign_in as a user I breakpoint in "../devise/sessions_controller.rb#sign_in" and that all works
fine when I continue.
The status change gives me a "sign_out" link in my applications.html layout but when I click
there I get above routine error. I don't get breakpoints in "../application_controller.rb"
or "../devise/sessions_controller.rb#sign_out"
Here is routes.rb
Demo::Application.routes.draw do
# replace devise_for :users with:
devise_for :users, :controllers => { :registrations => "devise/registrations" }
get "user/show"
get "user/edit"
get "user/index"
get "user/create"
get "user/update"
get "user/new"
resources :users
resources :orders
resources :carts
resources :line_items
resource :store do
member do
get "store/index"
end
end
match ':controller(/:action(/:id(.:format)))'
root to: 'store#index'
end
And rake:routes
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
user_show GET /user/show(.:format) {:controller=>"user", :action=>"show"}
user_edit GET /user/edit(.:format) {:controller=>"user", :action=>"edit"}
user_index GET /user/index(.:format) {:controller=>"user", :action=>"index"}
user_create GET /user/create(.:format) {:controller=>"user", :action=>"create"}
user_update GET /user/update(.:format) {:controller=>"user", :action=>"update"}
user_new GET /user/new(.:format) {:controller=>"user", :action=>"new"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
carts GET /carts(.:format) {:action=>"index", :controller=>"carts"}
POST /carts(.:format) {:action=>"create", :controller=>"carts"}
new_cart GET /carts/new(.:format) {:action=>"new", :controller=>"carts"}
edit_cart GET /carts/:id/edit(.:format) {:action=>"edit", :controller=>"carts"}
cart GET /carts/:id(.:format) {:action=>"show", :controller=>"carts"}
PUT /carts/:id(.:format) {:action=>"update", :controller=>"carts"}
DELETE /carts/:id(.:format) {:action=>"destroy", :controller=>"carts"}
line_items GET /line_items(.:format) {:action=>"index", :controller=>"line_items"}
POST /line_items(.:format) {:action=>"create", :controller=>"line_items"}
new_line_item GET /line_items/new(.:format) {:action=>"new", :controller=>"line_items"}
edit_line_item GET /line_items/:id/edit(.:format) {:action=>"edit", :controller=>"line_items"}
line_item GET /line_items/:id(.:format) {:action=>"show", :controller=>"line_items"}
PUT /line_items/:id(.:format) {:action=>"update", :controller=>"line_items"}
DELETE /line_items/:id(.:format) {:action=>"destroy", :controller=>"line_items"}
store_index_store GET /store/store/index(.:format) {:controller=>"store/store", :action=>"index"}
store POST /store(.:format) {:action=>"create", :controller=>"stores"}
new_store GET /store/new(.:format) {:action=>"new", :controller=>"stores"}
edit_store GET /store/edit(.:format) {:action=>"edit", :controller=>"stores"}
GET /store(.:format) {:action=>"show", :controller=>"stores"}
PUT /store(.:format) {:action=>"update", :controller=>"stores"}
DELETE /store(.:format) {:action=>"destroy", :controller=>"stores"}
/:controller(/:action(/:id(.:format)))
root / {:controller=>"store", :action=>"index"}
Robin
Change your link to
<%= link_to('Logout', destroy_user_session_path, :method=>'delete') %>
e.g. add `:method=>'delete'

Weird Routing Issue - No Method Error

I'm getting a no method error when loading form for a nested resource. I have a fix for it but it's not right I'm sure.
My routes.rb contains:
resources :orders do
resources :comments, :technicals, :milestones
end
At the top of my techncials.html.erb form I have this:
<%= semantic_form_for([#order, #technical]) do |f| %>
When loading the form, I get an error:
> NoMethodError in Technicals#new
>
> undefined method `technicals_path' for
> #<#<Class:0x00000102118318>:0x000001020ec470>
If I then put this in my routes, it all works just fine:
resources :technicals, :only => [ :create ]
What on earth am I doing wrong, if anything??!
Edit: I think My models etc. are all set up correctly:
class Technical < ActiveRecord::Base
belongs_to :order
end
-- edit --
company_order_comments GET /companies/:company_id/orders/:order_id/comments(.:format) {:action=>"index", :controller=>"comments"}
POST /companies/:company_id/orders/:order_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_company_order_comment GET /companies/:company_id/orders/:order_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_company_order_comment GET /companies/:company_id/orders/:order_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
company_order_comment GET /companies/:company_id/orders/:order_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /companies/:company_id/orders/:order_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /companies/:company_id/orders/:order_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
company_orders GET /companies/:company_id/orders(.:format) {:action=>"index", :controller=>"orders"}
POST /companies/:company_id/orders(.:format) {:action=>"create", :controller=>"orders"}
new_company_order GET /companies/:company_id/orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_company_order GET /companies/:company_id/orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
company_order GET /companies/:company_id/orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /companies/:company_id/orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /companies/:company_id/orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
companies GET /companies(.:format) {:action=>"index", :controller=>"companies"}
POST /companies(.:format) {:action=>"create", :controller=>"companies"}
new_company GET /companies/new(.:format) {:action=>"new", :controller=>"companies"}
edit_company GET /companies/:id/edit(.:format) {:action=>"edit", :controller=>"companies"}
company GET /companies/:id(.:format) {:action=>"show", :controller=>"companies"}
PUT /companies/:id(.:format) {:action=>"update", :controller=>"companies"}
DELETE /companies/:id(.:format) {:action=>"destroy", :controller=>"companies"}
order_comments GET /orders/:order_id/comments(.:format) {:action=>"index", :controller=>"comments"}
POST /orders/:order_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_order_comment GET /orders/:order_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_order_comment GET /orders/:order_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
order_comment GET /orders/:order_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /orders/:order_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /orders/:order_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
order_technicals GET /orders/:order_id/technicals(.:format) {:action=>"index", :controller=>"technicals"}
POST /orders/:order_id/technicals(.:format) {:action=>"create", :controller=>"technicals"}
new_order_technical GET /orders/:order_id/technicals/new(.:format) {:action=>"new", :controller=>"technicals"}
edit_order_technical GET /orders/:order_id/technicals/:id/edit(.:format) {:action=>"edit", :controller=>"technicals"}
order_technical GET /orders/:order_id/technicals/:id(.:format) {:action=>"show", :controller=>"technicals"}
PUT /orders/:order_id/technicals/:id(.:format) {:action=>"update", :controller=>"technicals"}
DELETE /orders/:order_id/technicals/:id(.:format) {:action=>"destroy", :controller=>"technicals"}
order_milestones GET /orders/:order_id/milestones(.:format) {:action=>"index", :controller=>"milestones"}
POST /orders/:order_id/milestones(.:format) {:action=>"create", :controller=>"milestones"}
new_order_milestone GET /orders/:order_id/milestones/new(.:format) {:action=>"new", :controller=>"milestones"}
edit_order_milestone GET /orders/:order_id/milestones/:id/edit(.:format) {:action=>"edit", :controller=>"milestones"}
order_milestone GET /orders/:order_id/milestones/:id(.:format) {:action=>"show", :controller=>"milestones"}
PUT /orders/:order_id/milestones/:id(.:format) {:action=>"update", :controller=>"milestones"}
DELETE /orders/:order_id/milestones/:id(.:format) {:action=>"destroy", :controller=>"milestones"}
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
/orders(.:format) {:controller=>"orders", :action=>"index"}
root /(.:format) {:controller=>"home", :action=>"index"}
NoMethodError in Technicals#new
Does controllers/technicals_controller.rb have a "def new"?
If not, try adding one:
def new
#technical = Technical.new
end

Singular resources namespaced by its slug (Routing)

I have the followed Rails 3 routes:
Hello::Application.routes.draw do
resources :blogs do
resources :articles do
resources :comments
end
end
end
By raking them, we can find:
GET /blogs/:blog_id/articles/:article_id/comments(.:format) {:action=>"index", :controller=>"comments"}
blog_article_comments POST /blogs/:blog_id/articles/:article_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_blog_article_comment GET /blogs/:blog_id/articles/:article_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
GET /blogs/:blog_id/articles/:article_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /blogs/:blog_id/articles/:article_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
blog_article_comment DELETE /blogs/:blog_id/articles/:article_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
edit_blog_article_comment GET /blogs/:blog_id/articles/:article_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
GET /blogs/:blog_id/articles(.:format) {:action=>"index", :controller=>"articles"}
blog_articles POST /blogs/:blog_id/articles(.:format) {:action=>"create", :controller=>"articles"}
new_blog_article GET /blogs/:blog_id/articles/new(.:format) {:action=>"new", :controller=>"articles"}
GET /blogs/:blog_id/articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /blogs/:blog_id/articles/:id(.:format) {:action=>"update", :controller=>"articles"}
blog_article DELETE /blogs/:blog_id/articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}
edit_blog_article GET /blogs/:blog_id/articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
GET /blogs(.:format) {:action=>"index", :controller=>"blogs"}
blogs POST /blogs(.:format) {:action=>"create", :controller=>"blogs"}
new_blog GET /blogs/new(.:format) {:action=>"new", :controller=>"blogs"}
GET /blogs/:id(.:format) {:action=>"show", :controller=>"blogs"}
PUT /blogs/:id(.:format) {:action=>"update", :controller=>"blogs"}
blog DELETE /blogs/:id(.:format) {:action=>"destroy", :controller=>"blogs"}
edit_blog GET /blogs/:id/edit(.:format) {:action=>"edit", :controller=>"blogs"}
Because every routes begin with the same root path (/blogs), I would like to shorten addresses by removing it (when :blog_id is given).
In this why, I could have thoses routes (I think it's more DRY):
GET /:blog_id/articles/:article_id/comments(.:format) {:action=>"index", :controller=>"comments"}
blog_article_comments POST /:blog_id/articles/:article_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_blog_article_comment GET /:blog_id/articles/:article_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
GET /:blog_id/articles/:article_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /:blog_id/articles/:article_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
blog_article_comment DELETE /:blog_id/articles/:article_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
edit_blog_article_comment GET /:blog_id/articles/:article_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
GET /:blog_id/articles(.:format) {:action=>"index", :controller=>"articles"}
blog_articles POST /:blog_id/articles(.:format) {:action=>"create", :controller=>"articles"}
new_blog_article GET /:blog_id/articles/new(.:format) {:action=>"new", :controller=>"articles"}
GET /:blog_id/articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /:blog_id/articles/:id(.:format) {:action=>"update", :controller=>"articles"}
blog_article DELETE /:blog_id/articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}
edit_blog_article GET /:blog_id/articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
GET /blogs(.:format) {:action=>"index", :controller=>"blogs"}
blogs POST /blogs(.:format) {:action=>"create", :controller=>"blogs"}
new_blog GET /blogs/new(.:format) {:action=>"new", :controller=>"blogs"}
GET /blogs/:id(.:format) {:action=>"show", :controller=>"blogs"}
PUT /blogs/:id(.:format) {:action=>"update", :controller=>"blogs"}
blog DELETE /blogs/:id(.:format) {:action=>"destroy", :controller=>"blogs"}
edit_blog GET /blogs/:id/edit(.:format) {:action=>"edit", :controller=>"blogs"}
According to you, what kind of change I should make over my current routes configuration?
Thanks.
My opinion is that you need to look at shallow routes. To my knowledge the customisation you are asking is not achievable using route resources and I don't think it's desirable.
Where you have defined one to many relationships you do not need to pass the identifier for each of the nested resources. This is considered bad practice (by some, though not others). For example, instead of this long url:
/blog/:blog_id/articles/:article_id/comments/:id
#controller
#blog = Blog.find params[:blog_id]
#article = Blog.find params[:article_id]
#comment = Comment.find params[:id]
you actually need only:
/comments/:id
#controller
#comment = Comment.find params[:id]
#article = #comment.article
#blog = #article.blog
More info:
http://railscasts.com/episodes/139-nested-resources
"Resources should never be nested more than 1 level deep." (http://guides.rubyonrails.org/routing.html)
If the Rails documentation is making this strong of a recommendation I have no idea why it is allowed still.

Uninitialized constant problem for Rails routes

Here's my route configuration:
map.resources :services do |services|
services.resources :capabilities do |capabilities|
capabilities.resources :http_headers
end
end
Here's my "rake routes" output:
laran:trunk laran$ rake routes
(in /Users/laran/workspace/kibo/mega/server/trunk)
accounts GET /accounts(.:format) {:action=>"index", :controller=>"accounts"}
POST /accounts(.:format) {:action=>"create", :controller=>"accounts"}
new_account GET /accounts/new(.:format) {:action=>"new", :controller=>"accounts"}
edit_account GET /accounts/:id/edit(.:format) {:action=>"edit", :controller=>"accounts"}
account GET /accounts/:id(.:format) {:action=>"show", :controller=>"accounts"}
PUT /accounts/:id(.:format) {:action=>"update", :controller=>"accounts"}
DELETE /accounts/:id(.:format) {:action=>"destroy", :controller=>"accounts"}
services GET /services(.:format) {:action=>"index", :controller=>"services"}
POST /services(.:format) {:action=>"create", :controller=>"services"}
new_service GET /services/new(.:format) {:action=>"new", :controller=>"services"}
edit_service GET /services/:id/edit(.:format) {:action=>"edit", :controller=>"services"}
service GET /services/:id(.:format) {:action=>"show", :controller=>"services"}
PUT /services/:id(.:format) {:action=>"update", :controller=>"services"}
DELETE /services/:id(.:format) {:action=>"destroy", :controller=>"services"}
service_capabilities GET /services/:service_id/capabilities(.:format) {:action=>"index", :controller=>"capabilities"}
POST /services/:service_id/capabilities(.:format) {:action=>"create", :controller=>"capabilities"}
new_service_capability GET /services/:service_id/capabilities/new(.:format) {:action=>"new", :controller=>"capabilities"}
edit_service_capability GET /services/:service_id/capabilities/:id/edit(.:format) {:action=>"edit", :controller=>"capabilities"}
service_capability GET /services/:service_id/capabilities/:id(.:format) {:action=>"show", :controller=>"capabilities"}
PUT /services/:service_id/capabilities/:id(.:format) {:action=>"update", :controller=>"capabilities"}
DELETE /services/:service_id/capabilities/:id(.:format) {:action=>"destroy", :controller=>"capabilities"}
service_capability_http_headers GET /services/:service_id/capabilities/:capability_id/http_headers(.:format) {:action=>"index", :controller=>"http_headers"}
POST /services/:service_id/capabilities/:capability_id/http_headers(.:format) {:action=>"create", :controller=>"http_headers"}
new_service_capability_http_header GET /services/:service_id/capabilities/:capability_id/http_headers/new(.:format) {:action=>"new", :controller=>"http_headers"}
edit_service_capability_http_header GET /services/:service_id/capabilities/:capability_id/http_headers/:id/edit(.:format) {:action=>"edit", :controller=>"http_headers"}
service_capability_http_header GET /services/:service_id/capabilities/:capability_id/http_headers/:id(.:format) {:action=>"show", :controller=>"http_headers"}
PUT /services/:service_id/capabilities/:capability_id/http_headers/:id(.:format) {:action=>"update", :controller=>"http_headers"}
DELETE /services/:service_id/capabilities/:capability_id/http_headers/:id(.:format) {:action=>"destroy", :controller=>"http_headers"}
/login {:action=>"login", :controller=>"accounts"}
/logout {:action=>"logout", :controller=>"accounts"}
root / {:action=>"index", :controller=>"default"}
laran:trunk laran$
When I go to /services/new though, I get this error:
NameError in ServicesController#new
uninitialized constant ServicesController::Services
What gives? How can I get things working and routed correctly? Thanks.
Is ServicesController backed up by a model Service? Did you accidentally reference it as Services in your controller?
This probably doesn't have anything to do with your routes; your new method in ServicesController is trying to use a (class? constant? object?) named Services that doesn't exist.

Resources