How to create an action with two params

I’m implementing an action that needs two parameters in the url like

do/a/b

and in the controller
I would like to access a and b

like params[:id]

Please let me know if there’s any solution.

THanks

Abon

Bontina C. wrote:

I’m implementing an action that needs two parameters in the url like

do/a/b

and in the controller
I would like to access a and b

like params[:id]

Please let me know if there’s any solution.

In routes.rb create something like:

map.connect ‘do/:a/:b’, :controller => “do”, :action => “index”

In controller “do” :a and :b will be accessible as params[:a] and
params[:b].


Michael W.

THanks for the solution.
Btw, it seems not ok to have tow ids in link_to.

Abon
Michael W. wrote:

Bontina C. wrote:

I’m implementing an action that needs two parameters in the url like

do/a/b

and in the controller
I would like to access a and b

like params[:id]

Please let me know if there’s any solution.

In routes.rb create something like:

map.connect ‘do/:a/:b’, :controller => “do”, :action => “index”

In controller “do” :a and :b will be accessible as params[:a] and
params[:b].


Michael W.

Bontina C. wrote:

THanks for the solution.
Btw, it seems not ok to have tow ids in link_to.

In the link_to helper method, any parameters that you specify will be
matched
to the route that Rails is going to use, and any “extra” parameters
(parameters not named in the route) will be tacked on as URL query
parameters.

So you can do:

link_to “link name”, :controller => “do”, :action => “index”, :a =>
“a_blah”,
"b => “b_blah”, :c => “c_blah”

and you get (using the route in my previous post):

link_name


Michael W.

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