Strange error.... ActionController::RoutingError

Hello, i have a problem, had a table called news and other called news_images, the first é for save news and other for save url for images associated with news. Make migrations for each table manual and db:migrate after that i run scaffold for news, and generate model for news_image... put has_many and belongs_to in file_column on news_image model and ok.... when i try access page for new News i get this error:

ActionController::RoutingError in News#new news_url failed to generate from {:action=>"show", :controller=>"news"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["news", :id] - are they all satisfied?

Extracted source (around line #5):

2: 3: <%= error_messages_for :news %> 4: 5: <% form_for(@news) do |f| %>

I don't understand why, i don't had any other route with same name in routes.rb, i can't had tables with names like news?

Obrigado .

Some one can help?

Daniel Lopes :

Hello, i have a problem, had a table called news and other called news_images, the first é for save news and other for save url for images associated with news. Make migrations for each table manual and db:migrate after that i run scaffold for news, and generate model for news_image... put has_many and belongs_to in file_column on news_image model and ok.... when i try access page for new News i get this error:

ActionController::RoutingError in News#new news_url failed to generate from {:action=>"show", :controller=>"news"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["news", :id] - are they all satisfied?

The word news is uncountable, so you have to specify a :singular option with map.resources.

see : http://somethinglearned.com/articles/2007/03/19/how-to-uncountable-names-in-restful-routes

    -- Jean-François.

Understand Jean, thanks.

Hello all!

I still don't understand, what to do in news/edit.html.erb

when I try to get /news/1/edit (news with this id exists, of course) i see following:

NoMethodError in News#edit

Showing news/edit.html.erb where line #9 raised:

You have a nil object when you didn't expect it! The error occurred while evaluating nil.to_sym

Extracted source (around line #9):

6: <div class="errors"> 7: <%= error_messages_for :news %> 8: </div> 9: <% form_for(@news) do |f| %>

link to edit looks like: <%= link_to 'Edit', edit_news_instance_path(news), :class=>"button long" %>

In routes.rb:

map.resources :news, :singular => 'news_instance'

All other are works, except edit...

You aren’t defining @news in your edit method definition in your news controller

Actually the problem is not that @news is not defined in the edit action (it might be an additional problem)

The way I see it, he :singular option is only used to create the the url-generation methods for the resource (e.g. edit_news_instance_path, etc.)

This option however is not used by the form_for @news call to deduct the name of the url-generation-method. It just gets the singular class name of the News class from the inflections, hence instead of edit_news_instance_path, edit_news_path is called, which, of course, does not exist.

A workaround might be specifying the :url option in form_for, although I've had trouble with this, too, at least when using namespaced resources.

I hope this helps

Daniel Lopes wrote:

Hello, i have a problem...

In file: your_app_name\config\initializers\inflections.rb   add string: inflect.uncountable %w( news )   and read comments

me wrote:

In file: your_app_name\config\initializers\inflections.rb   add string: inflect.uncountable %w( news )   and read comments

My appologies, add :

Inflector.inflections do |inflect| inflect.uncountable %w( news ) end