Is there an easy way to add a .html extension to the end of all URLs? I''ve tried adding this to routes.rb: map.connect '':controller/:action/:id.html'', :format => ''html'' or this to the ApplicationController: def default_url_options(options) { :format => ''html'' } end but neither of these methods renders the right link with the link_to tag <%= link_to ''Show'', post] %> Do I have to use <a href="<%= url_for(post) %>.html"> or is there a more elegant solution? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matthew Rudy Jacobs
2008-Jul-14 08:52 UTC
Re: Easy way to add .html extension to all URLs?
et wrote:> Is there an easy way to add a .html extension to the end of all URLs? > > I''ve tried adding this to routes.rb: > map.connect '':controller/:action/:id.html'', :format => ''html''> but neither of these methods renders the right link with the link_to > tag <%= link_to ''Show'', post] %> > > Thanks!Where did you put that extra route? Routes are matched in the order they feature in your routes.rb file so, map.admin ''admin/:action/:id.html'', :controller => ''admin'', :format => "html" .... map.connect '':controller/:action/:id.html'', :format => "html" map.connect '':controller/:action.html'', :format => "html" # now the defaults map.connect '':controller/:action/:id.:format'' map.connect '':controller/:action/:id should generate with .html for you, but why do you want this? by all means provide a legacy fallback to .html, but moving forward, why is it good to depend on this extension? -- 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 -~----------~----~----~----~------~----~------~--~---
I have the extra route above the default ones, but is there a way to generate "/posts/1.html" using <%= link_to ''Show'', post %> or a simpler method than what I have above? Right now /posts/1.html works if I navigate directly to it, but the links on the views/posts/index.html.erb are still rendering as /posts/ 1 The reason I want the extension is to make sure search engines will see /posts/1.html as a document in the first level directory as opposed to /posts/1 as a second deeper level directory. On Jul 14, 4:52 am, Matthew Rudy Jacobs <rails-mailing-l...@andreas- s.net> wrote:> et wrote: > > Is there an easy way to add a .html extension to the end of all URLs? > > > I''ve tried adding this to routes.rb: > > map.connect '':controller/:action/:id.html'', :format => ''html'' > > but neither of these methods renders the right link with the link_to > > tag <%= link_to ''Show'', post] %> > > > Thanks! > > Where did you put that extra route? > > Routes are matched in the order they feature in your routes.rb file > > so, > > map.admin ''admin/:action/:id.html'', :controller => ''admin'', :format => > "html" > .... > > map.connect '':controller/:action/:id.html'', :format => "html" > map.connect '':controller/:action.html'', :format => "html" > > # now the defaults > map.connect '':controller/:action/:id.:format'' > map.connect '':controller/:action/:id > > should generate with .html for you, > but why do you want this? > > by all means provide a legacy fallback to .html, > but moving forward, > why is it good to depend on this extension? > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---