3
votes

After creating a database in the command line and migrating it, I cannot get rails to route properly to "http://localhost:3000/blog_entries" -- it simply displays the default view, the same as just "http://localhost:3000". If I add the code rails generated in the blog_entries index.html.erb into the application.html.erb view, it displays the results one would expect.

rake routes gives me the following:

      blog_entries GET    /blog_entries(.:format)          blog_entries#index
                POST   /blog_entries(.:format)          blog_entries#create
 new_blog_entry GET    /blog_entries/new(.:format)      blog_entries#new
edit_blog_entry GET    /blog_entries/:id/edit(.:format) blog_entries#edit
     blog_entry GET    /blog_entries/:id(.:format)      blog_entries#show
                PUT    /blog_entries/:id(.:format)      blog_entries#update
                DELETE /blog_entries/:id(.:format)      blog_entries#destroy
           root        /                                home#index

My routes.rb contains the following (atm... have searched hours for a solution, everything i've tried has failed):

RubydRailed::Application.routes.draw do

  resources :blog_entries do
    get "blog_entries"
  end

end

I am very new to rails, and really am having trouble understanding why rails is routing to application.html.erb for the URL "http://localhost:3000/blog_entries". I have looked over the documentation, searched google and stakoverflow for a few hours now and I just can't figure it out on my own. Help is greatly appreciated -- I'm sure the answer is simple but I just don't get it.

1
remove get "blog_entries", it's wrong, just use resources :blog_entriesThanh

1 Answers

3
votes

application is your layout. There is <%= yield %> in it, this yield is rendering the view of current controller/action. In other words your layout (application.html.erb) rendering with each request and specific view for request rendered inside of it. %br

Also delete index.html from the public/ directory.