2

I'm stuck on a Rails 2.3 app trying to redirect some old URLs. I'm new to RoR and know 3+ way better, so I'm having trouble getting this done.

So: http://siteurl.com/foo/:foo_id goes to http://siteurl.com/foo/:foo_id/foo_items

I think I'm close because the end product goes to: http://siteurl.com/foo/foo_id/foo_items but doesn't pass the :foo_id params it actually writes it out!

Any help, or pointers are much appreciated.

In my routes.rb

map.connect '/foo/:foo_id',
      :controller => 'redirect',
      :action => :redirectoldfoo,
      :monkey_tag => ':foo_id'

In my redirect controller:

  def redirectoldfoo
    redirect_to "/auctions/#{params[:monkey_tag]}/catalog_items"
  end
jdl
  • 17,702
  • 4
  • 51
  • 54
jahrichie
  • 1,215
  • 3
  • 17
  • 26

1 Answers1

1

You should not need the :monkey_tag at all, since :foo_id is all you're using anyway.

  map.connect '/foo/:foo_id',
      :controller => 'redirect',
      :action => :redirectoldfoo

  def redirectoldfoo
    redirect_to "/auctions/#{params[:foo_id]}/catalog_items"
  end

Note that in your example you indicated that you were trying to redirect to both /foo/:foo_id/foo_items and then /auctions/:foo_id/catalog_items. I assumed that the second one was closer to the real code, so I left that one in there.

jdl
  • 17,702
  • 4
  • 51
  • 54
  • A+. I'm always overcomplicating – jahrichie Sep 11 '12 at 02:39
  • I realize I'm late to the party, but how would this work for making http://www.siteurl.com into http://siteurl.com ? This would be a huge help for an old Rails project I'm fixing. – KDP Oct 14 '13 at 14:58
  • Hi @KDP. You should handle that in the web server if possible, but it is possible to do it in Rails as well. Either way, this is well traveled ground with plenty of answers on this site as well as serverfault.com. – jdl Oct 14 '13 at 15:20