0

I created a scaffold without problems

$ rails generate scaffold New name:string title:string content:text

Rake command to run the migration (no problems as before, table correctly created)

$ rake db:migrate

Edit app/views/home/index.html.erb

<%= link_to 'My News', :controller => 'news' %>

I see the home and the link correctly in "http://localhost:3000"; clicking the link "My news" page "http://localhost:3000/news" is loaded without errors.

Now, clicking in the link "New New" generated by Rails, link's target localhost:3000/news/new (source "<a href ="/news/new">New New</ a>"), i read this error:

Routing Error

No route matches {:action=>"show", :controller=>"news", :format=>nil}

Try running rake routes for more information on available routes.

In "app/views/news/index.html.erb" the link souce is

<%= link_to 'New New', new_news_path %>

In routes.rb i read

MyApp::Application.routes.draw do

resources :news

get "home/index"

  • Rails 3.2.3
  • Ruby 1.9.3p125
  • MySQL 5.5
  • Windows 7 64 bit

Rakes routes:

news_index GET /news(.:format) news#index

POST /news(.:format) news#create

new_news GET /news/new(.:format) news#new

edit_news GET /news/:id/edit(.:format) news#edit

news GET /news/:id(.:format) news#show

PUT /news/:id(.:format) news#update

DELETE /news/:id(.:format) news#destroy

home_index GET /home/index(.:format) home#index

root / home#index

Thanks in advance and sorry for my English

2
  • What is the generated link's target? Could you copy that row from the generated source? Commented Apr 26, 2012 at 14:52
  • Yes, the link's target is localhost:3000/news/new Commented Apr 26, 2012 at 14:53

1 Answer 1

1

you have to use news_index_path because news is not singular if rails can't make singular - prular distinguish they will add _index at the end :)

You have one news and many news and this is confusing.

Always try to use <name_of_resource>_path to generate urls :)

news_index GET /news(.:format) news#index

This says it implicit, you use 1 part news_index and add _path to get path for it.

You should have

<%= link_to 'My News', news_index_path %>

Hope that helps, cheers!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but i changed ":controller => 'news'" with "news_index_path" in "app/views/home/index.html.erb" and i have the same error clicking on "New New". In "app/views/news/index.html.erb" the link is "<%= link_to 'New New', new_news_path %>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.