Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Root Route issues?

Hey folks i am having some issues with rails root routs. For some reason I can not get root url (localhost:3000/) to route to the appropriate place.

I have built a brand new app and used scaffold to generate the "questions" model. I can confirm that the"index" action exists (by default from scaffold)

Here is my code:

Fbauth::Application.routes.draw do
  resources :questions
  root :to => 'questions#index'
end

Rake Routes Output:

 (in /home/jsfour/rails3_apps/fbauth)
    questions GET    /questions(.:format)          {:action=>"index", :controller=>"questions"}
              POST   /questions(.:format)          {:action=>"create", :controller=>"questions"}
 new_question GET    /questions/new(.:format)      {:action=>"new", :controller=>"questions"}
edit_question GET    /questions/:id/edit(.:format) {:action=>"edit", :controller=>"questions"}
     question GET    /questions/:id(.:format)      {:action=>"show", :controller=>"questions"}
              PUT    /questions/:id(.:format)      {:action=>"update", :controller=>"questions"}
              DELETE /questions/:id(.:format)      {:action=>"destroy", :controller=>"questions"}
         root        /(.:format)                   {:controller=>"questions", :action=>"index"}

What is the problem here? Why is localhost:3000/ giving me the "welcome to rails" message?

like image 596
jsfour Avatar asked Dec 11 '10 20:12

jsfour


People also ask

How do I use the root method in rails?

You can specify what Rails should route '/' to with the root method: You should put the root route at the top of the file, because it is the most popular route and should be matched first. The root route only routes GET requests to the action. You can also use root inside namespaces and scopes as well. For example:

What is resource routing in rails 2?

2 Resource Routing: the Rails Default. Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index, show, new, edit, create, update and destroy actions, a resourceful route declares them in a single line of code.

What is each method in resource route in rails?

Each method is a request to perform an operation on the resource. A resource route maps a number of related requests to actions in a single controller. When your Rails application receives an incoming request for: it asks the router to map it to a controller action. If the first matching route is:

How do you request a resource in rails?

Browsers request pages from Rails by making a request for a URL using a specific HTTP method, such as GET, POST, PATCH, PUT and DELETE. Each method is a request to perform an operation on the resource. A resource route maps a number of related requests to actions in a single controller.


1 Answers

You need to delete public/index.html - it will have priority over your root action.

like image 182
Reuben Mallaby Avatar answered Nov 04 '22 13:11

Reuben Mallaby