Rick
2009-Jul-04 02:20 UTC
I''m stumped by this stupid newbie error I''m seeing... trying to figure out where to "look" next... (undefined method xxx_path )
On one of my new.html.erb files backed by a "matches_controller" I''m getting the error: undefined method `matches_path'' for #<ActionView::Base:0x2cfc748> I don''t understand where to start looking to try to understand why I''m getting this error. Even if I back everything out of the page and just have: <h1>New match</h1> <% form_for(@match) do |f| %> <% end %> I still get the error. What am I supposed to do to start tracking now where the issue is? Is it that I''m getting an error message that isn''t directly related at all to the ''matches_path" issue. Other pages aren''t having this issue, so I''m a bit stumped. I''m a rails newb (but seasoned java person so I have no problem looking in logs for errors.. but the errors don''t seem to be helping me track down the ''reai'' issue.) Thanks for any direction of what to start looking at (is it maybe an obscure error in my controller or another page causing the problem?)
Älphä Blüë
2009-Jul-04 02:36 UTC
Re: I''m stumped by this stupid newbie error I''m seeing... trying to figure out where to "look" next
Don''t feel bad mate - everyone here was a newb at one time or another. I''m still in my newb phase too :)... So, first question I have to ask is are you using RESTful controllers? In otherwords, are you generating a scaffold and having all 7 RESTful methods created for you automatically? index, new, show, create, edit, update, and destroy By using REST, the controllers, the views, the models are all setup initially for you.. -- Posted via http://www.ruby-forum.com/.
Matt Harrison
2009-Jul-04 03:16 UTC
Re: I''m stumped by this stupid newbie error I''m seeing... trying to figure out where to "look" next... (undefined method xxx_path )
Rick wrote:> On one of my new.html.erb files backed by a "matches_controller" I''m > getting the error: > > undefined method `matches_path'' for #<ActionView::Base:0x2cfc748> > > I don''t understand where to start looking to try to understand why I''m > getting this error. Even if I back everything out of the page and just > have: > > <h1>New match</h1> > <% form_for(@match) do |f| %> > <% end %> > > I still get the error. > > What am I supposed to do to start tracking now where the issue is? Is > it that I''m getting an error message that isn''t directly related at > all to the ''matches_path" issue. > Other pages aren''t having this issue, so I''m a bit stumped.I''m still a relative newby, so no worries :) It''s a routing problem. The form_for tries to generate a route relating to the matches controller, but the route doesn''t exist. Either you want to add something like map.resources :matches to config/routes.rb, or manually add a route in that same file, pointing to the controller/action you want. The resources mapping will generate a whole load of routes for that controller that use the RESTful principles. You can add that above line and then run "rake routes" to list the structure. The new routes generate buy the line will be shown and should let you see what it does. HTH Matt
Rick
2009-Jul-04 03:41 UTC
Re: I''m stumped by this stupid newbie error I''m seeing... trying to figure out where to "look" next... (undefined method xxx_path )
On Fri, Jul 3, 2009 at 11:16 PM, Matt Harrison<iwasinnamuknow-ja4MoDZtUtVl57MIdRCFDg@public.gmane.org> wrote:> It''s a routing problem. The form_for tries to generate a route relating > to the matches controller, but the route doesn''t exist. Either you want > to add something like > > map.resources :matches > > to config/routes.rb, or manually add a route in that same file, pointing > to the controller/action you want. The resources mapping will generate a > whole load of routes for that controller that use the RESTful principles. > > You can add that above line and then run "rake routes" to list the > structure. The new routes generate buy the line will be shown and should > let you see what it does.Awesome. Thanks so much! I had created the other pages using the scaffolding (which explains those entries in the routes.rb) but not for this one (matches) which I manually started to make. Scaffolding is nice but learn so much more from these mistakes doing it yourself that you helped me with . Thanks again.
Älphä Blüë
2009-Jul-04 13:42 UTC
Re: I''m stumped by this stupid newbie error I''m seeing... trying to figure out where to "look" next
Rick wrote:> On Fri, Jul 3, 2009 at 11:16 PM, Matt > Harrison<iwasinnamuknow-ja4MoDZtUtVl57MIdRCFDg@public.gmane.org> wrote: > >> You can add that above line and then run "rake routes" to list the >> structure. The new routes generate buy the line will be shown and should >> let you see what it does. > > Awesome. Thanks so much! I had created the other pages using the > scaffolding (which explains those entries in the routes.rb) but not > for this one (matches) which I manually started to make. Scaffolding > is nice but learn so much more from these mistakes doing it yourself > that you helped me with . Thanks again.Yep, scaffolding is one of those things everyone, including myself - finds out about later on. Then there''s always some unloved MVC that gets forgotten in the shuffle. Again, glad you got everything working out. Routing is very important and one of the intricate parts of rails. You can also limit your routing for each of those scaffolds by doing something similar: Say you want to restrict the route only to the index and you have RESTful methods in each of your scaffolds.. you can do : map.resources :name_of_controller, ''/route'' You can also name specific routes/custom actions by.. map.name_of_route :name_of_route, :controller => ''name_of_controller'', :action => ''custom_method'' And, you can also further provide a catchall route for anything not specified in your routes by doing the following: map.connect "*anything", :controller => ''your_controller'', :action => ''request_error_page'' Place this one at the very bottom of your routes and create a custom view named request_error_page.html.erb and you can intercept anything that''s out of scope. Routing is also important with where you place things. For instance, this last line if you placed it at the top of your routes file, it would catch everything and none of your other routes would work. -- Posted via http://www.ruby-forum.com/.
Älphä Blüë
2009-Jul-04 13:44 UTC
Re: I''m stumped by this stupid newbie error I''m seeing... trying to figure out where to "look" next
> > map.resources :name_of_controller, ''/route'' >Correcting the first entry - don''t know how that copy and paste got in there: map.resources :name_of_controller, :only => :index -- Posted via http://www.ruby-forum.com/.