Okay so right now I have this as a route: map.connect ''browse/:cal_name'', :controller => ''browse'', :action => ''events_listing'' If the :cal_name has spaces in it (Test Calendar) for example, then the url appears as Test+Calendar in the url. Is there a way to substitute something else (say ''-'' or something) for the ''+'' in the url? Thanks for your help :) -- 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 -~----------~----~----~----~------~----~------~--~---
> Okay so right now I have this as a route: > > map.connect ''browse/:cal_name'', :controller => ''browse'', :action => > ''events_listing'' > > If the :cal_name has spaces in it (Test Calendar) for example, then the > url appears as Test+Calendar in the url. Is there a way to substitute > something else (say ''-'' or something) for the ''+'' in the url?I''d mix things up a little bit. I''m going to assume some things about your model names, but that''s not the important part :) class Calendar < ActiveRecord::Base # assuming the following columns: id:integer, name:string def to_param "#{id}-#{name.gsub(/[^a-z0-9]+/i, ''-'').downcase}" rescue id end end Then change your route to this: map.browse_calendar ''browse/:calendar'', :controller => ''browse'', :action => ''events_listing'' Then in your controller do this: @calendar = Calendar.find(123) # assuming id=123 is ''Test Calendar'' And in your view do this: <%= link_to ''Browse'', browse_calendar_path(:calendar => @calendar) %> That should result in a URL such as: /browse/123-test-calendar If for some reason doing the substition in that to_param() method fails you will get: /browse/123 In either case you can then use that information in your events_listing action to retrive the calendar using: Calendar.find_by_id(params[:calendar]) You could also change the to_param() method to not put the "123-" at the beginning, but would then need to tweak your finding later on to look for either an id or a calendar name. Hope this helps, -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Is there a way to just alter the :cal_name (i.e. gsub('' '', ''-'')) or something in the route? I''m a newbie so bare with me...this is probably completely obvious >< -- 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 -~----------~----~----~----~------~----~------~--~---
> Is there a way to just alter the :cal_name (i.e. gsub('' '', ''-'')) or > something in the route? I''m a newbie so bare with me...this is probably > completely obvious ><Yes. Exactly what you have above will work...> -- > 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> Is there a way to just alter the :cal_name (i.e. gsub('' '', ''-'')) or >> something in the route? I''m a newbie so bare with me...this is probably >> completely obvious >< > > Yes. > > Exactly what you have above will work...but how do I get it to do the gsub in the middle of a string? -- 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 -~----------~----~----~----~------~----~------~--~---
> Philip Hallstrom wrote: >>> Is there a way to just alter the :cal_name (i.e. gsub('' '', ''-'')) or >>> something in the route? I''m a newbie so bare with me...this is probably >>> completely obvious >< >> >> Yes. >> >> Exactly what you have above will work... > > but how do I get it to do the gsub in the middle of a string?<%= link_to ''browse'', {:action => ''event_listing'', :cal_name => "Test Calendar".gsub('' '', ''-'')} %> -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
doing "browse/#{:calname.gsub('' '', ''-'')}" doesn''t work -- 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 -~----------~----~----~----~------~----~------~--~---
Amanda .. wrote:> doing "browse/#{:calname.gsub('' '', ''-'')}" doesn''t workhaha bad timing, okay i''ll try that -- 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:> > <%= link_to ''browse'', {:action => ''event_listing'', :cal_name => "Test > Calendar".gsub('' '', ''-'')} %> > > -philipOkay the problem with this is that the actual :cal_name with spaces is really important in my code...maybe I should just add another parameter? -- 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 -~----------~----~----~----~------~----~------~--~---
Amanda .. wrote:> Okay the problem with this is that the actual :cal_name with spaces is > really important in my code...maybe I should just add another parameter?Nevermind if I add another parameter, it just puts :cal_name on the end of it lol...is there a way to use gsub right in map.connect ''browse/:cal_name'', :controller => ''browse'', :action => ''events_listing''? -- 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 -~----------~----~----~----~------~----~------~--~---
Okay figured out a way to do it..completely inefficient though :) -- 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 -~----------~----~----~----~------~----~------~--~---