I can''t figure out how to make the updates to allow for the route_form method to return a url that matches the expected. Here is a sample route_for(:controller => :task, :action => :new).should == "/task/new" If a task has to be created for a user, how exactly do I do this. The following doesn''t work: route_for(:controller => :task, :action => :new, :user_id => 1).should == "/users/1/task/new" (fails) route_for(:controller => :task, :action => :new, :user_id => 1).should == "/task/new?user_id=1" (passes) Or do you just use: new_user_task(1,1).should == "/users/1/task/new" I haven''t been able to find that much documentation on the route_for method that lists any ways of creating the nested route url. Thanks. -- Posted via http://www.ruby-forum.com/.
Chris Olsen wrote:> I can''t figure out how to make the updates to allow for the route_form > method to return a url that matches the expected.Sorry to bump such an old post, but the interweb doesn''t really show anything for routing specs when it comes to nested resources. I just find this unanswered post repeatedly. Does anyone know how to work with route_for() when it comes to nested resources? -- Posted via http://www.ruby-forum.com/.
On Nov 21, 2007 3:10 PM, Chris Olsen <lists at ruby-forum.com> wrote:> I can''t figure out how to make the updates to allow for the route_form > method to return a url that matches the expected. > > Here is a sample > route_for(:controller => :task, :action => :new).should == "/task/new" > > If a task has to be created for a user, how exactly do I do this. The > following doesn''t work: > route_for(:controller => :task, :action => :new, :user_id => 1).should > == "/users/1/task/new" (fails) > route_for(:controller => :task, :action => :new, :user_id => 1).should > == "/task/new?user_id=1" (passes) > > Or do you just use: > new_user_task(1,1).should == "/users/1/task/new" > > I haven''t been able to find that much documentation on the route_for > method that lists any ways of creating the nested route url.It uses ActionController::Routing::Routes.generate, which is equally un-documented :( You''ve got a singular task controller (instead of tasks), so I''m not sure how that''s affecting things. I can tell you that if you do this: route_for(:controller => ''tasks'', :action => ''new'', :user_id => ''2'').should == ''/users/2/tasks/new'' It will pass when your routes.rb has this: map.resources :users do |users| users.resources :tasks end Give that a whirl. Cheers, David> > Thanks. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Jan 27, 2008 6:27 PM, Matt Darby <lists at ruby-forum.com> wrote:> Chris Olsen wrote: > > I can''t figure out how to make the updates to allow for the route_form > > method to return a url that matches the expected. > > > Sorry to bump such an old post, but the interweb doesn''t really show > anything for routing specs when it comes to nested resources. I just > find this unanswered post repeatedly. > > Does anyone know how to work with route_for() when it comes to nested > resources?I think I answered that in my response to the OP. Write back if not.> > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Jan 27, 2008, at 8:05 PM, David Chelimsky wrote:> On Nov 21, 2007 3:10 PM, Chris Olsen <lists at ruby-forum.com> wrote: >> I can''t figure out how to make the updates to allow for the >> route_form >> method to return a url that matches the expected. >> >> Here is a sample >> route_for(:controller => :task, :action => :new).should == "/task/ >> new" >> >> If a task has to be created for a user, how exactly do I do this. >> The >> following doesn''t work: >> route_for(:controller => :task, :action => :new, :user_id => >> 1).should >> == "/users/1/task/new" (fails) >> route_for(:controller => :task, :action => :new, :user_id => >> 1).should >> == "/task/new?user_id=1" (passes) >> >> Or do you just use: >> new_user_task(1,1).should == "/users/1/task/new" >> >> I haven''t been able to find that much documentation on the route_for >> method that lists any ways of creating the nested route url. > > It uses ActionController::Routing::Routes.generate, which is equally > un-documented :( > > You''ve got a singular task controller (instead of tasks), so I''m not > sure how that''s affecting things. I can tell you that if you do this: > > route_for(:controller => ''tasks'', :action => ''new'', :user_id => > ''2'').should == ''/users/2/tasks/new'' > > It will pass when your routes.rb has this: > > map.resources :users do |users| > users.resources :tasks > end > > Give that a whirl. > > Cheers, > DavidThanks for the further explanation David! I could''ve sworn that I tried this, but sure enough, it works like a charm. Thanks! Matt Darby, M.S. IT Manager / Lead Web Developer Dynamix Engineering Ltd. 1108 City Park Ave. Columbus, OH 43206 Cell: (614) 403-5289 www.dynamix-ltd.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/2f98f42d/attachment-0001.html
Note, named routes cannot be accessed unless you have a response (eg after you''ve run a controller action) See http://rspec.lighthouseapp.com/projects/5645/tickets/201-enable- named-urls-before-response On Jan 27, 2008, at 8:26 PM, Matt Darby wrote:> On Jan 27, 2008, at 8:05 PM, David Chelimsky wrote: > >> On Nov 21, 2007 3:10 PM, Chris Olsen <lists at ruby-forum.com> wrote: >>> Or do you just use: >>> new_user_task(1,1).should == "/users/1/task/new" >>> >>>-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/9d049a9f/attachment.html
On Jan 27, 2008 7:47 PM, Jonathan Linowes <jonathan at parkerhill.com> wrote:> Note, named routes cannot be accessed unless you have a response (eg after > you''ve run a controller action) > See > http://rspec.lighthouseapp.com/projects/5645/tickets/201-enable-named-urls-before-responseSince you bring it up - any ideas on how to make that happen?> > > > On Jan 27, 2008, at 8:26 PM, Matt Darby wrote: > > > On Jan 27, 2008, at 8:05 PM, David Chelimsky wrote: > > On Nov 21, 2007 3:10 PM, Chris Olsen <lists at ruby-forum.com> wrote: > > Or do you just use: > new_user_task(1,1).should == "/users/1/task/new" > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Maybe Matching Threads
- undefined method `route_for' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:
- ZenTest-3.9.0 incompatible with RSpec-1.1.2
- Textmate RSpec Bundle ''it'' snippet
- Changes in specs for routes in rspec 1.1.99.x
- How to spec routes for a resource nested in multiples resources?