rerouting between controller's actions *WITHOUT REDIRECT_TO*

Hello everyone, I need to implement first level permalink style url routing inside my rails application, ie: /first_link.html /another_one.html ... /last_one.html

For each permalink there's an associated record (model: Permalink) so that: permalink = Permalink.find_by_url("first_link.html") # the following gives me the action and controller associated to the permalink permalink.app_action permalink.app_action.app_controller

to handle the routing of these permalinks I'm forced to use this, inside my routes.rb: map.connect(':permalink.html', :controller => "permalinks", :action => "drive")

class PermalinksController < ApplicationController def drive() permalink = Permalink.find_by_url(params[:permalink]) # TODO HERE end end

the entire site is based on these kind of permalinks, so I'd like to reroute the execution flow from Permalinks::drive() to the controller's action specified by the selected permalink.

The only constraint I can't avoid is that I can't use redirect_to because it would rewrite the browser's url and I need to keep the same url for the entire request.

How can I achieve this?

(I hope this will be a builtin feature )

Thx@ll

Well, that's isn't something easy to get going :slight_smile:

What you need to do is remove this "permalink" controller and implement the urls using permalinks for each model/controller pair that requires them.

Quoting maurizio de magnis <maurizio.demagnis@gmail.com>:

Hello everyone, I need to implement first level permalink style url routing inside my rails application, ie: /first_link.html /another_one.html ... /last_one.html

For each permalink there's an associated record (model: Permalink) so that: permalink = Permalink.find_by_url("first_link.html") # the following gives me the action and controller associated to the permalink permalink.app_action permalink.app_action.app_controller

to handle the routing of these permalinks I'm forced to use this, inside my routes.rb: map.connect(':permalink.html', :controller => "permalinks", :action => "drive")

class PermalinksController < ApplicationController def drive() permalink = Permalink.find_by_url(params[:permalink]) # TODO HERE end end

the entire site is based on these kind of permalinks, so I'd like to reroute the execution flow from Permalinks::drive() to the controller's action specified by the selected permalink.

The only constraint I can't avoid is that I can't use redirect_to because it would rewrite the browser's url and I need to keep the same url for the entire request.

How can I achieve this?

I've not tried it, but can Ruby proc objects be serialized? If so, just store the appropriate method call, and call it after setting params.

HTH,   Jeffrey

Nops, procs can't be serialized, but you could (at your own risk) serialize a string with the code and then eval it.

Unfortunately this solution can't be adopted since one of my constraints is to avoid having nested directories in the url, so I can't use something like /mycontroller/my_link.html, I'm forced to use /my_link_about_my_controller.html instead.

And don't be fooled by the pattern I've just used! Urls get generated in an unpredictable (by routes.rb) way.

One solution I'm currently trying is by adopting "apotomo" plugin which is based upon the "cells" plugin.

The latter, which is extremely simple, could've solved my problem but the first is even more powerful so I'm digging in with that :wink:

thx for sharing your thoughts btw :slight_smile: