Hello all, Here''s a newbie question (4 weeks and counting). My routes.rb is as below. map.resources :projects, :departments, :users, :admins, :imports, :notes #Below is route in question map.resources :projects, :collection => { :view_all => :get } map.home '''', :controller => ''projects'', :action => ''index'' map.connect '':controller/:action/:id.:format'' map.connect '':controller/:action/:id'' I''m tried to get a url like this: http://localhost:3000/projects/view_all I have a view_all in the ProjectsController and I have a view_all template. When I type in the desired url, I get this error: "ActiveRecord::RecordNotFound in ProjectsController#show Couldn''t find Project with ID=view_all" Thank you for any help. JohnM -- Posted via http://www.ruby-forum.com/.
ROR will attempt to find routes from the top of the file first and then move on to the rest of the file. It would seem that you have listed projects twice: map.resources :*projects*, :departments, :users, :admins, :imports, :notes #Below is route in question map.resources :*projects*, :collection => { :view_all => :get } The first one (without the :collection) would be used. Hope this helps. On Fri, Aug 28, 2009 at 11:34 AM, John Mcleod < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello all, > Here''s a newbie question (4 weeks and counting). > My routes.rb is as below. > > map.resources :projects, :departments, :users, :admins, :imports, :notes > > #Below is route in question > map.resources :projects, :collection => { :view_all => :get } > > map.home '''', :controller => ''projects'', :action => ''index'' > map.connect '':controller/:action/:id.:format'' > map.connect '':controller/:action/:id'' > > I''m tried to get a url like this: > http://localhost:3000/projects/view_all > > I have a view_all in the ProjectsController and I have a view_all > template. > > When I type in the desired url, I get this error: > > "ActiveRecord::RecordNotFound in ProjectsController#show > > Couldn''t find Project with ID=view_all" > > Thank you for any help. > > JohnM > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Mcleod wrote:> Hello all, > Here''s a newbie question (4 weeks and counting). > My routes.rb is as below. > > map.resources :projects, :departments, :users, :admins, :imports, :notes > > #Below is route in question > map.resources :projects, :collection => { :view_all => :get } > > map.home '''', :controller => ''projects'', :action => ''index'' > map.connect '':controller/:action/:id.:format'' > map.connect '':controller/:action/:id'' > > I''m tried to get a url like this: > http://localhost:3000/projects/view_all > > I have a view_all in the ProjectsController and I have a view_all > template. > > When I type in the desired url, I get this error: > > "ActiveRecord::RecordNotFound in ProjectsController#show > > Couldn''t find Project with ID=view_all" > > Thank you for any help. > > JohnMYour view_all == default index That being said, when you add a controller method like view_all, you''ll need to tell the routes about it (add view_all as a get method for the collection) map.resources :projects, :collection => {:view_all => :get} -- Posted via http://www.ruby-forum.com/.
Another tip is to run "rake routes" to see all the available routes. On Aug 28, 9:26 am, James Englert <englert.ja...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ROR will attempt to find routes from the top of the file first and then move > on to the rest of the file. It would seem that you have listed projects > twice: > > map.resources :*projects*, :departments, :users, :admins, :imports, :notes > > #Below is route in question > map.resources :*projects*, :collection => { :view_all => :get } > > The first one (without the :collection) would be used. > > Hope this helps. > > On Fri, Aug 28, 2009 at 11:34 AM, John Mcleod < > > rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Hello all, > > Here''s a newbie question (4 weeks and counting). > > My routes.rb is as below. > > > map.resources :projects, :departments, :users, :admins, :imports, :notes > > > #Below is route in question > > map.resources :projects, :collection => { :view_all => :get } > > > map.home '''', :controller => ''projects'', :action => ''index'' > > map.connect '':controller/:action/:id.:format'' > > map.connect '':controller/:action/:id'' > > > I''m tried to get a url like this: > >http://localhost:3000/projects/view_all > > > I have a view_all in the ProjectsController and I have a view_all > > template. > > > When I type in the desired url, I get this error: > > > "ActiveRecord::RecordNotFound in ProjectsController#show > > > Couldn''t find Project with ID=view_all" > > > Thank you for any help. > > > JohnM > > -- > > Posted viahttp://www.ruby-forum.com/.
On Aug 28, 2009, at 11:34 AM, John Mcleod wrote:> Hello all, > Here''s a newbie question (4 weeks and counting). > My routes.rb is as below. > > map > .resources :projects, :departments, :users, :admins, :imports, :notes > > #Below is route in question > map.resources :projects, :collection => { :view_all => :get }Routes have preference based on their order of appearance. The first time you create routes for :projects, there''s a show route like / projects/:id and that matches before the second one. Combine those into: map.resources :projects, :collection => { :view_all => :get } map.resources :departments, :users, :admins, :imports, :notes HOWEVER, the regular route: /projects is normally going to show you all the projects anyway. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > map.home '''', :controller => ''projects'', :action => ''index'' > map.connect '':controller/:action/:id.:format'' > map.connect '':controller/:action/:id'' > > I''m tried to get a url like this: > http://localhost:3000/projects/view_all > > I have a view_all in the ProjectsController and I have a view_all > template. > > When I type in the desired url, I get this error: > > "ActiveRecord::RecordNotFound in ProjectsController#show > > Couldn''t find Project with ID=view_all" > > Thank you for any help. > > JohnM > -- >
Since I''ve been learning rails, I thought that routes are the linking of the "Controller" Object to their "Action" method. When you set up RESTful routing, you need to add custom or named routes after the default 7. To set up custom or named routes, you use "map.connect" "path/to/view", :controller => ''controller'', :aciton => ''action'' Is this correct or am I lost? Rob Biedenharn wrote:> On Aug 28, 2009, at 11:34 AM, John Mcleod wrote: >> Hello all, >> Here''s a newbie question (4 weeks and counting). >> My routes.rb is as below. >> >> map >> .resources :projects, :departments, :users, :admins, :imports, :notes >> >> #Below is route in question >> map.resources :projects, :collection => { :view_all => :get } > > Routes have preference based on their order of appearance. The first > time you create routes for :projects, there''s a show route like / > projects/:id and that matches before the second one. > > Combine those into: > > map.resources :projects, :collection => { :view_all => :get } > map.resources :departments, :users, :admins, :imports, :notes > > HOWEVER, the regular route: > /projects > is normally going to show you all the projects anyway. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org-- Posted via http://www.ruby-forum.com/.
Hi John, try this approach: in the Product class add this function- require ''uri'' def self.find_custom arg object = self.new object.id = URI.escape(arg) object end and in the controller try calling as: Product.find_custom(params[:id]).view_all just try it, and let me know. On Fri, Aug 28, 2009 at 9:04 PM, John Mcleod < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello all, > Here''s a newbie question (4 weeks and counting). > My routes.rb is as below. > > map.resources :projects, :departments, :users, :admins, :imports, :notes > > #Below is route in question > map.resources :projects, :collection => { :view_all => :get } > > map.home '''', :controller => ''projects'', :action => ''index'' > map.connect '':controller/:action/:id.:format'' > map.connect '':controller/:action/:id'' > > I''m tried to get a url like this: > http://localhost:3000/projects/view_all > > I have a view_all in the ProjectsController and I have a view_all > template. > > When I type in the desired url, I get this error: > > "ActiveRecord::RecordNotFound in ProjectsController#show > > Couldn''t find Project with ID=view_all" > > Thank you for any help. > > JohnM > -- > Posted via http://www.ruby-forum.com/. > > > >-- Regards, Himanshu --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Mcleod wrote:> Since I''ve been learning rails, I thought that routes are the linking of > the "Controller" Object to their "Action" method. > When you set up RESTful routing, you need to add custom or named routes > after the default 7.I tend to think of it as adding them ''inline'' As Rob suggested:>> Combine those into:map.resources :projects, :collection => { :view_all => :get } The above line gets you the default routes, and adds a route that works on the projects collection called ''view_all'' and is a GET request. Just what your view_all route will do is up to the controller code for that method, but we assumed that you''re returning all the projects, which is what ''index'' does. Hence my earlier point that your ''show_all'' is functionally the same as the default ''index'', and unnecessary... There is also the ability to add routes that deal with a specific project. You''d specify this type of route using the :member specification. map.resources :projects, :member => {:as_pdf => :get} This route is intended to operate against a single project, and is a GET request. My app has a project model as well, and it''s map.resources line looks like this: map.resources :projects, :member => {:as_pdf => :get, :clone => :get, :trace => :get} This yields the index, show, new, create, edit, update, and destroy standard routes, as well as: an ''as_pdf'' route (to generate a pdf of the project info), a ''clone'' route (makes a deep clone of an existing project), and a ''trace'' route which generates a traceability view of the project) Run a rake routes >routes.lst command from the root of your app, then look insude routes.lst to see what''s being generated for you by restful routing. It''s very informative. -- Posted via http://www.ruby-forum.com/.
On Aug 28, 2009, at 2:02 PM, John Mcleod wrote:> Since I''ve been learning rails, I thought that routes are the > linking of the "Controller" Object to their "Action" method. > When you set up RESTful routing, you need to add custom or named > routes after the default 7. > To set up custom or named routes, you use "map.connect" "path/to/ > view", > :controller => ''controller'', :aciton => ''action'' > > Is this correct or am I lost?Not lost, just not yet there. As you''ve no doubt seen from other responses, you had :projects in BOTH places. Personally, I never define more than one resource route at a time. map.resources :projects, :collection => { :view_all => :get } map.resources :departments map.resources :users map.resources :admins map.resources :imports map.resources :notes If you need to add other routes to them, you''ll need to pull separate them anyway. -Rob> > Rob Biedenharn wrote: >> On Aug 28, 2009, at 11:34 AM, John Mcleod wrote: >>> Hello all, >>> Here''s a newbie question (4 weeks and counting). >>> My routes.rb is as below. >>> >>> map >>> .resources >>> :projects, :departments, :users, :admins, :imports, :notes >>> >>> #Below is route in question >>> map.resources :projects, :collection => { :view_all => :get } >> >> Routes have preference based on their order of appearance. The first >> time you create routes for :projects, there''s a show route like / >> projects/:id and that matches before the second one. >> >> Combine those into: >> >> map.resources :projects, :collection => { :view_all => :get } >> map.resources :departments, :users, :admins, :imports, :notes >> >> HOWEVER, the regular route: >> /projects >> is normally going to show you all the projects anyway. >> >> -Rob >> >> Rob Biedenharn http://agileconsultingllc.com >> Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > -- > Posted via http://www.ruby-forum.com/. > > >
On Aug 28, 2:43 pm, Himanshu Prakash <vision2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi John, > try this approach: > in the Product class add this function- > > require ''uri'' > def self.find_custom arg > object = self.new > object.id = URI.escape(arg) > object > end > > and in the controller try calling as: > Product.find_custom(params[:id]).view_all > > just try it, and let me know.This code is so messed up it''s almost not even wrong. What exactly is it supposed to do? --Matt Jones