Hello list, I''m a fairly nooby Rails developer of very little brain, and this error has had me confused for the last several hours. It''s a very simple (unfinished) Rails app. It has a model called Tasks. It has a very basic routes.rb resources :tasks root :to => ''tasks#index'' A vanilla controller (create action not properly defined yet because that would have been next on the list when I ran into this problem) class TasksController < ApplicationController def index @tasks = Tasks.all end def new @task = Tasks.new end def create end end And a view for the /tasks/new action <h1>Create new task</h1> <%= form_for @task do |form| %> <%= lots of form. blah blah here... %> <% end %> And when the view is rendered I get the following error: undefined method `tasks_index_path'' for #<#<Class:0x000000020c04e8>:0x000000020b74d8> Extracted source (around line *#2*): 1: <h1>Create new task</h1> 2: <%= form_for @task do |form| %> And here are the top few lines of the stack trace: actionpack (3.0.0) lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'' actionpack (3.0.0) lib/action_dispatch/routing/polymorphic_routes.rb:120:in `polymorphic_path'' actionpack (3.0.0) lib/action_view/helpers/form_helper.rb:335:in `apply_form_for_options!'' actionpack (3.0.0) lib/action_view/helpers/form_helper.rb:307:in `form_for'' app/views/tasks/new.html.erb:2:in `_app_views_tasks_new_html_erb__194514136627382544_17145340__4434388515179536201'' I don''t really understand where "tasks_index_path" came from or why form_for has bombed out so spectacularly, especially given how simple the code is right now. Can anyone point me at what I might be doing wrong? Oh yes, it''s rails 3.0.0 on ruby 1.9.2 running on Ubuntu 10.04. Thanks, Mark -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Hello list, >Hi Mark,> I''m a fairly nooby Rails developer of very little brain, and this error has > had me confused for the last several hours. > > It''s a very simple (unfinished) Rails app. It has a model called Tasks. It > has a very basic routes.rb > > resources :tasks > root :to => ''tasks#index'' > > A vanilla controller (create action not properly defined yet because that > would have been next on the list when I ran into this problem) > > class TasksController < ApplicationController > > def index > @tasks = Tasks.all > end > > def new > @task = Tasks.new > end > > def create > end > > endmodels are always singular in rails. Try the following: def index @tasks = Task.all end def new @task = Task.new end That should help. Regards, Max.> And a view for the /tasks/new action > > <h1>Create new task</h1> > <%= form_for @task do |form| %> > <%= lots of form. blah blah here... %> > <% end %> > > And when the view is rendered I get the following error: > > undefined method `tasks_index_path'' for > #<#<Class:0x000000020c04e8>:0x000000020b74d8> > > Extracted source (around line *#2*): > > 1: <h1>Create new task</h1> > 2: <%= form_for @task do |form| %> > > And here are the top few lines of the stack trace: > > actionpack (3.0.0) > lib/action_dispatch/routing/polymorphic_routes.rb:114:in > `polymorphic_url'' > actionpack (3.0.0) > lib/action_dispatch/routing/polymorphic_routes.rb:120:in > `polymorphic_path'' > actionpack (3.0.0) lib/action_view/helpers/form_helper.rb:335:in > `apply_form_for_options!'' > actionpack (3.0.0) lib/action_view/helpers/form_helper.rb:307:in `form_for'' > app/views/tasks/new.html.erb:2:in > `_app_views_tasks_new_html_erb__194514136627382544_17145340__4434388515179536201'' > > I don''t really understand where "tasks_index_path" came from or why form_for > has bombed out so spectacularly, especially given how simple the code is > right now. Can anyone point me at what I might be doing wrong? > > Oh yes, it''s rails 3.0.0 on ruby 1.9.2 running on Ubuntu 10.04. > > Thanks, > > Mark >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 October 2010 09:35, Maksim Gudovsikov <gudovsikov-jv+WEUQhfkc@public.gmane.org> wrote:> > models are always singular in rails. Try the following: > > def index > @tasks = Task.all > end > > def new > @task = Task.new > end > > That should help. > > Regards, Max. > > >Mmm, perhaps you meant that all models *should* be singular in rails. Mine weren''t! However after a couple of quick search-and-replaces I had a singular Task model and suddenly the form_for error went away. Interesting side-effect. Maybe warnings about pluralised models in the docs need to be in really BIG RED LETTERS so that idiots like me will notice them. Anyway, thanks for the reply. Mark -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mark Weston wrote:> On 7 October 2010 09:35, Maksim Gudovsikov <gudovsikov-jv+WEUQhfkc@public.gmane.org> wrote: >> >> That should help. >> >> Regards, Max. >> >> >> > Mmm, perhaps you meant that all models *should* be singular in rails. > Mine > weren''t! However after a couple of quick search-and-replaces I had a > singular Task model and suddenly the form_for error went away. > Interesting > side-effect. Maybe warnings about pluralised models in the docs need to > be > in really BIG RED LETTERS so that idiots like me will notice them.Remember: try to name your classes after what they actually represent! A Task object represents one Task, so you really *shouldn''t* call it Tasks.> > Anyway, thanks for the reply. > > MarkBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.