I''ve set up my app to display a post by retrieving its title instead of id, which works fine, except it looks like this "/post/the+title+of+post%3F" and I want it to be "the_title_of_post?" with underscores instead of plusses. Can anyone shed light? -- Posted via http://www.ruby-forum.com/.
On Wed, Jan 04, 2006 at 08:21:19AM +0100, Kyle Jones wrote:> I''ve set up my app to display a post by retrieving its title instead of > id, which works fine, except it looks like this > "/post/the+title+of+post%3F" and I want it to be "the_title_of_post?" > with underscores instead of plusses. Can anyone shed light?You could define Post#to_param like this: class Post < ActiveRecord::Base def to_param title.gsub(/\s+/, ''_'') end end Then: link_to @post.title, :action => ''show'', :id => @post or link_to @post.title, show_post_url(:id => @post) to_param will be called implicitly. marcel -- Marcel Molina Jr. <marcel@vernix.org>
That works at least to create the desired URL, but now i still have to find_by_post with it, and it doesnt like the new underscores. also how would you retain characters like "?" instead of "%3F" ? -- Posted via http://www.ruby-forum.com/.
Kyle Jones wrote:> That works at least to create the desired URL, but now i still have to > find_by_post with it, and it doesnt like the new underscores. also how > would you retain characters like "?" instead of "%3F" ?find_by_title my bad :-P -- Posted via http://www.ruby-forum.com/.
Kyle Jones wrote:> I''ve set up my app to display a post by retrieving its title instead of > id, which works fine, except it looks like this > "/post/the+title+of+post%3F" and I want it to be "the_title_of_post?" > with underscores instead of plusses. Can anyone shed light?maybe the plugin acts_as_urlnameable from http://gironda.org/acts_as_urlnameable/ could help you. -- 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 -~----------~----~----~----~------~----~------~--~---
or even acts_as_sluggable. http://dev.2750flesk.com/acts_as_sluggable/ On 12/30/06, docpepin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Kyle Jones wrote: > > I''ve set up my app to display a post by retrieving its title instead of > > id, which works fine, except it looks like this > > "/post/the+title+of+post%3F" and I want it to be "the_title_of_post?" > > with underscores instead of plusses. Can anyone shed light? > > maybe the plugin acts_as_urlnameable from > http://gironda.org/acts_as_urlnameable/ > could help you. > > -- > 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 -~----------~----~----~----~------~----~------~--~---