Getting Started: 5 Getting Up and Running

70 views
Skip to first unread message

Dave Lindberg

unread,
Jan 24, 2016, 12:39:33 PM1/24/16
to Ruby on Rails: Documentation
First foray into Rails, and everything's smooth until I hit step 5 in the Getting Started docs. 

After adding the article resource to config/routes.rb:

  # Adding a new resource, as per initial guide, 
  # "Getting Up and Running":
  Rails.application.routes.draw do
    resources :articles
    root 'welcome#index'
  end


I receive the following error at http://localhost:3000/articles/new:

ArgumentError

Invalid route name, already in use: 'root' You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

 with an indication that the issue is at "root 'welcome#index'"

What am I missing here?

Enter code here...

Ryan Bigg

unread,
Jan 24, 2016, 3:02:21 PM1/24/16
to rubyonra...@googlegroups.com
Could you please show us your complete config/routes.rb?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Documentation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-do...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-docs.
For more options, visit https://groups.google.com/d/optout.

Dave Lindberg

unread,
Jan 24, 2016, 7:44:01 PM1/24/16
to Ruby on Rails: Documentation
Thx,  looks like I figured it out. I had inserted the article resource within the body of the 'welcome/index' resource. 

My current config/routes.rb file now looks lie this, and all is good:

Rails.application.routes.draw do
  get 'welcome/index'

  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  # root 'welcome#index'

  
  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end
# Adding a new resource, as per initial guide, 
# "Getting Up and Running":
Rails.application.routes.draw do
  resources :articles do
    resources :comments
  end
  root 'welcome#index'
end

Ryan Bigg

unread,
Jan 24, 2016, 8:02:16 PM1/24/16
to rubyonra...@googlegroups.com
You're defining two Rails.application.routes.draw blocks there. You should only be defining one.
Reply all
Reply to author
Forward
0 new messages