match “programs/:id” => “Programs#your_action_name”, :as => :list
So in your controller ‘Programs’ you are able to handle the request with the “id” which will be variable, and the path can be called by ‘list_path’. The action you’ll call here will handle the request and you may then list the rows accordingly…
In my opinion you should let controller handle the size of your list, if it is ‘programs/1’, ‘programs/2’ or ‘programs/3’ it will look for :controller => programs, :action => your_defined_action . So, in there in your action you just need to manipulate the params[:id] and according to it generate your data. For e.g. - if :id is 1 then generate your short_list, for 2 medium_list and for 3 long_list. Since, this all will be handle with in one action defined with in a controller it will be very compact and DRY, and can be viewed in a template. 3njoy
In my opinion you should let controller handle the size of your list, if it is ‘programs/1’, ‘programs/2’ or ‘programs/3’ it will look for :controller => programs, :action => your_defined_action . So, in there in your action you just need to manipulate the params[:id] and according to it generate your data. For e.g. - if :id is 1 then generate your short_list, for 2 medium_list and for 3 long_list. Since, this all will be handle with in one action defined with in a controller it will be very compact and DRY, and can be viewed in a template. 3njoy
thanks , That’s better than what I did first,
but is there any way to match to a specific name ( short_list,
medium_list, long_list ) based upon the parameter 1, 2, 3
I think you’re asking about this:
match ‘/short_list’ => “Programs#list”, :list_id => 1, :as => ‘short_list’
match ‘/medium_list’ => “Programs#list”, :list_id => 2, :as => ‘medium_list’
match ‘/long_list’ => “Programs#list”, :list_id => 3, :as => ‘long_list’
The URL has the word and the controller gets a number as the parameter.
match “programs/:id” => “Programs#your_action_name”, :as => :list
So in your controller ‘Programs’ you are able to handle the request with the
“id” which will be variable, and the path can be called by ‘list_path’. The
action you’ll call here will handle the request and you may then list the
rows accordingly…
I would like to have some more friendly URLS …
I have some routes , with parameters I would like to rewrite but I
don’t know if it’s possible :