[Nitro] Idiom to pass multiple parameters

George Moschovitis george.moschovitis at gmail.com
Mon Sep 5 03:25:26 EDT 2005


Have you tried the default 'nice' dispatcher?

it maps url of the form:

my_action/x/y/z

to

def my_action(x, y, z)
  ..
end

If you want a different mapping for example:

my_action/par1/x/par2/y/par3/z

to 

def my_action(par1, par2, par3)
end

you could write (and donate ;-)) another dispatcher ;-)

regards,
George.

On 9/4/05, Aleksi Niemela <Aleksi.Niemela at cs.helsinki.fi> wrote:
> I know this is the usual way to introduce an action:
> 
>   def categories
>     # do something useful with @category
>   end
>   action :categories, :route => /category\/(.*)/, 'category' => nil
> 
> But how should I pass on multiple parameters? Url format of
> 
>    /foo/84/bar/3902
> 
> doesn't look outright horrible but can stay quite pretty for few
> parameters. It's surely more of a nuisance with dozens of parameters.
> Therefore I thought to go with
> 
>    /foo/84?bar=3902
> 
> Is this the "right way" to do it? If this is the path, is the following
> the way to get the parameters to use them?
> 
> foo.xhtml:
> <?r
>    uri = UriUtils.update_query_string("categories/#{@foo}",
> :kategoria=>ec.name)
> ?>
>    <a href="#{uri}">bar</a>
> 
> controller.rb:
>   def categories
>     params = UriUtils.query_string_to_hash(request.query_string)
>     @bar = params["bar"]
>     # use foo and bar in a useful way
>   end
>   action :categories, :route => /category\/(.*)/, 'category' => nil
> 
> I find this way quite a bit clumsy. But if that's the way to work around
> I guess I'm forced to write up interception for an action method to set
> instance variables behind the scenes and gotta do something for the url
> building too.
> 
> I hope I've missed some elementary step but couldn't find any more
> complex actions in Spark. It was Pager mixin that showed me this way.
> 
> Or should I start using session or head my way to Wee like page storing?
> 
>    - Aleksi
> 
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
> 


-- 
http://www.gmosx.com
http://www.navel.gr
http://www.nitrohq.com




More information about the Nitro-general mailing list