Sumit Srivastava
2012-Nov-28 08:42 UTC
Having two paths for a single action with different parameters
Hi, I have a controller named users and index action in it. By default I have the path get ''/users'' => ''users#index'', :as => ''users'' Now I want to create one more path with a different parameter being passed get ''/users/:city'' => ''users#index'', :as => ''list_users'' But this gives as error, No route matches {:controller=>"users"}. I ran rake routes and found the path I defined to be present over there but it doesn''t works. What shall be done to make this work. -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/dGIZ5Q1zlyYJ. For more options, visit https://groups.google.com/groups/opt_out.
Jordon Bedwell
2012-Nov-28 08:53 UTC
Re: Having two paths for a single action with different parameters
On Wed, Nov 28, 2012 at 2:42 AM, Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a controller named users and index action in it. By default I have > the path > > get ''/users'' => ''users#index'', :as => ''users'' > > Now I want to create one more path with a different parameter being passed > > get ''/users/:city'' => ''users#index'', :as => ''list_users'' > > But this gives as error, No route matches {:controller=>"users"}. > > I ran rake routes and found the path I defined to be present over there but > it doesn''t works. > > What shall be done to make this work.I''ve no experience with routes exactly like that (considering to me it seems illogical) but maybe Rails see the same broken logic, in that you are trying to define two routes to same action when one route /should/ be a /one action/ have you tried creating a new action in your controller and seeing if the error still happens? Example: "get "/users/:city" => "users#by_city", :as => "by_city" but since I''ve not seen the entire error and just what rails reports at the top are you sure UsersController has index? Are you sure it''s not User instead of Users (I don''t quite remember of Rails will do the plural game on routes like it does with tables via ActiveRecord.) -- 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 https://groups.google.com/groups/opt_out.
sumit srivastava
2012-Nov-28 08:57 UTC
Re: Having two paths for a single action with different parameters
Yes, I did try this but it didn''t. In fact, the custom route I defined, if I define it as following it works. get ''/users'' => ''users#index'', :as => ''list_users'' But as soon as I define the extra parameter with it, it fails. Same with defining a new action. Regards Sumit Srivastava The power of imagination makes us infinite... On 28 November 2012 14:23, Jordon Bedwell <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Nov 28, 2012 at 2:42 AM, Sumit Srivastava > <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > I have a controller named users and index action in it. By default I have > > the path > > > > get ''/users'' => ''users#index'', :as => ''users'' > > > > Now I want to create one more path with a different parameter being > passed > > > > get ''/users/:city'' => ''users#index'', :as => ''list_users'' > > > > But this gives as error, No route matches {:controller=>"users"}. > > > > I ran rake routes and found the path I defined to be present over there > but > > it doesn''t works. > > > > What shall be done to make this work. > > I''ve no experience with routes exactly like that (considering to me it > seems illogical) but maybe Rails see the same broken logic, in that > you are trying to define two routes to same action when one route > /should/ be a /one action/ have you tried creating a new action in > your controller and seeing if the error still happens? Example: "get > "/users/:city" => "users#by_city", :as => "by_city" but since I''ve not > seen the entire error and just what rails reports at the top are you > sure UsersController has index? Are you sure it''s not User instead of > Users (I don''t quite remember of Rails will do the plural game on > routes like it does with tables via ActiveRecord.) > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Nov-28 08:57 UTC
Re: Having two paths for a single action with different parameters
On Wed, Nov 28, 2012 at 4:42 PM, Sumit Srivastava < sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a controller named users and index action in it. By default I have > the path > > get ''/users'' => ''users#index'', :as => ''users'' > > Now I want to create one more path with a different parameter being passed > > get ''/users/:city'' => ''users#index'', :as => ''list_users'' > > But this gives as error, No route matches {:controller=>"users"}. >Where do you get this error? How are you calling the route? Do you get the error if you go to localhost:3000/users/my_city? I don''t see any error with this route. show the code that produces the error and we''ll go from there. Btw, you should be able to call that route like this list_users_path(''my_city'')> > I ran rake routes and found the path I defined to be present over there > but it doesn''t works. > > What shall be done to make this work. > > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/dGIZ5Q1zlyYJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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 https://groups.google.com/groups/opt_out.
Jordon Bedwell
2012-Nov-28 09:00 UTC
Re: Having two paths for a single action with different parameters
On Wed, Nov 28, 2012 at 2:57 AM, sumit srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, I did try this but it didn''t. In fact, the custom route I defined, if I > define it as following it works. > > get ''/users'' => ''users#index'', :as => ''list_users'' > > But as soon as I define the extra parameter with it, it fails. Same with > defining a new action.Is there anyway you can send us the entire trace to look at? You can post it to a github gist so you can delete it after a while if you need to, but it would be nice to see the actual trace so we can see what where is going on and advise you better. -- 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 https://groups.google.com/groups/opt_out.
sumit srivastava
2012-Nov-28 09:17 UTC
Re: Having two paths for a single action with different parameters
I just found that the value I was passing had a "." in it. And somehow this was creating problem. Not sure why. I experimented with other special characters and also by removing any of it and it started working fine. The power of imagination makes us infinite... On 28 November 2012 14:30, Jordon Bedwell <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Nov 28, 2012 at 2:57 AM, sumit srivastava > <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Yes, I did try this but it didn''t. In fact, the custom route I defined, > if I > > define it as following it works. > > > > get ''/users'' => ''users#index'', :as => ''list_users'' > > > > But as soon as I define the extra parameter with it, it fails. Same with > > defining a new action. > > Is there anyway you can send us the entire trace to look at? You can > post it to a github gist so you can delete it after a while if you > need to, but it would be nice to see the actual trace so we can see > what where is going on and advise you better. > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.
Jordon Bedwell
2012-Nov-28 09:20 UTC
Re: Having two paths for a single action with different parameters
On Wed, Nov 28, 2012 at 3:17 AM, sumit srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I just found that the value I was passing had a "." in it. And somehow this > was creating problem. Not sure why. I experimented with other specialAdd "value: /.*/" to the end of the /users/:city route. -- 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 https://groups.google.com/groups/opt_out.
sumit srivastava
2012-Nov-28 09:25 UTC
Re: Having two paths for a single action with different parameters
Thanks a lot. It worked but with slight modification. I used, :constraints => { :city => /.*/ } Regards Sumit Srivastava The power of imagination makes us infinite... On 28 November 2012 14:50, Jordon Bedwell <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> "value: /.*/"-- 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 https://groups.google.com/groups/opt_out.
rahul chandra
2012-Nov-28 10:02 UTC
Re: Having two paths for a single action with different parameters
well for understanding, If you add a symbol like(:city) in the routes it takes that as a variable and whenever you call that route you have to pass a variable like "*list_users_path(:city)*" or *"/users/(:city)".* On Wednesday, November 28, 2012 2:12:12 PM UTC+5:30, Sumit Srivastava wrote:> > Hi, > > I have a controller named users and index action in it. By default I have > the path > > get ''/users'' => ''users#index'', :as => ''users'' > > Now I want to create one more path with a different parameter being passed > > get ''/users/:city'' => ''users#index'', :as => ''list_users'' > > But this gives as error, No route matches {:controller=>"users"}. > > I ran rake routes and found the path I defined to be present over there > but it doesn''t works. > > What shall be done to make this work. >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/jzUDOS-PgWQJ. For more options, visit https://groups.google.com/groups/opt_out.
sumit srivastava
2012-Nov-28 10:08 UTC
Re: Re: Having two paths for a single action with different parameters
Thanks Rahul. If possible could you explain any more cases as I faced. It would be helpful. Regards Sumit Srivastava The power of imagination makes us infinite... On 28 November 2012 15:32, rahul chandra <richesrahul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> well for understanding, If you add a symbol like(:city) in the routes it > takes that as a variable and whenever you call that route you have to pass > a variable like "*list_users_path(:city)*" or *"/users/(:city)".* > > > On Wednesday, November 28, 2012 2:12:12 PM UTC+5:30, Sumit Srivastava > wrote: > >> Hi, >> >> I have a controller named users and index action in it. By default I have >> the path >> >> get ''/users'' => ''users#index'', :as => ''users'' >> >> Now I want to create one more path with a different parameter being passed >> >> get ''/users/:city'' => ''users#index'', :as => ''list_users'' >> >> But this gives as error, No route matches {:controller=>"users"}. >> >> I ran rake routes and found the path I defined to be present over there >> but it doesn''t works. >> >> What shall be done to make this work. >> > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/jzUDOS-PgWQJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.
rahul chandra
2012-Nov-28 11:33 UTC
Re: Re: Having two paths for a single action with different parameters
sure! no problem. On Wednesday, November 28, 2012, sumit srivastava wrote:> Thanks Rahul. If possible could you explain any more cases as I faced. It > would be helpful. > > Regards > Sumit Srivastava > > The power of imagination makes us infinite... > > > On 28 November 2012 15:32, rahul chandra <richesrahul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:_e({}, ''cvml'', ''richesrahul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org'');> > > wrote: > >> well for understanding, If you add a symbol like(:city) in the routes it >> takes that as a variable and whenever you call that route you have to pass >> a variable like "*list_users_path(:city)*" or *"/users/(:city)".* >> >> >> On Wednesday, November 28, 2012 2:12:12 PM UTC+5:30, Sumit Srivastava >> wrote: >> >>> Hi, >>> >>> I have a controller named users and index action in it. By default I >>> have the path >>> >>> get ''/users'' => ''users#index'', :as => ''users'' >>> >>> Now I want to create one more path with a different parameter being >>> passed >>> >>> get ''/users/:city'' => ''users#index'', :as => ''list_users'' >>> >>> But this gives as error, No route matches {:controller=>"users"}. >>> >>> I ran rake routes and found the path I defined to be present over there >>> but it doesn''t works. >>> >>> What shall be done to make this work. >>> >> -- >> 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<javascript:_e({}, ''cvml'', ''rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org'');> >> . >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:_e({}, ''cvml'', >> ''rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org'');>. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/jzUDOS-PgWQJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > 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<javascript:_e({}, ''cvml'', ''rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org'');> > . > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:_e({}, ''cvml'', > ''rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org'');>. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- Thanks & Regards *Rahul Chandra, Software Developer* MangoSense.Inc +91 9890252428 -- 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 https://groups.google.com/groups/opt_out.