views:

64

answers:

0

Hi all,

I want to be able to use friendly_id in a catch all route to render the page that it fetches.

for example

http://localhost:3000/business would render controller "pages" action"show" with id "business" without leaving the url above.

The aim of this is to avoid things like localhost:3000/pages/business and make shorter urls. I have added a catch all route as follows

map.connect '*slug', :controller => 'index', :action => 'render_slug_page'

I have managed to be able to search the Slug model that comes with friendly_id to find the item in the Slug table (that was so kindly created by friendly_id)

My 'render_slug_page' action is currently as follows

if params[:slug]
   foundslug = Slug.find_by_name(params[:slug].first)
   render :controller => "#{foundslug.sluggable_type.pluralize.downcase}", :action => "#{foundslug.name}"

else
   #do something else here
end

but for some reason this syntax doesn't like me. I have tried passing locals etc into this but no good.

redirect_to :controller => "#{foundslug.sluggable_type.pluralize.downcase}", :action => "#{foundslug.name}"

works, but that's not what I'm trying to achieve here. Can anyone shed some light on this?

Thanks in advance for any help.

Cheers, Matenia