Dynamic mapping in controller


I have used scaffold to create my rails project and hence I have a
database containing a table called “results” and when i call the “show”
action followed by the ID it brings up a list of the relative record and
its details.

What I want though is for if someone types in say
localhost/results/etab-mobile that it maps dynamically to
localhost/show/1 but keeps localhost/etab-mobile in the address bar. the
“etab-mobile” title is found in the database under “module_name” so can
be pulled out for use.

I know this can be done in the routes.rb folder statically but would
like to do it in the controller so that its not as static.

is this possible?




I think its possible only thru routes.rb, cannot be done in controller,
As i see, if you have “link_name” in your database for each page on
http://site.com/homepage -> redirects to /site/1
http://site.com/about -> /site/3
in table of “menus” its looks
id — link ----------- name — …
1 homepage Welcome to Homepage
3 about Everything about us

“link” field is used to be a “friendly” link and generated thru
i think is simpliest way.

look at http://eurobdc.com at their links.


that sounds like the way id like to do it but im having trouble getting
my head around how to code it:

at the moment i have

map.connect ‘etab-mobile’,
:controller => ‘results’,
:action => ‘show’,
:id => ‘1’

but id like that :id =>‘1’ to be loaded in from my database rather than
statically as I have other results that id like to show with id =2 and
id=3 and so on…

You cannot display dynamic results under the same route showing in the
address bar, except you use POST instead of GET

Maybe that would work … someone would type :
and the route would be:
map.connect ‘results/:module_name’,
:controller => ‘results’,
:action => ‘show’

then you have params[:module_name] available in your show action and
can pull the correct dataset from the DB
with find(:first, :conditions => [module_name =
or sth. similar.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs