I can answer part of this:
params[:controller] doesn''t have a ''/'' prefix
because it''s a parameter.
Just like params[:id]
The URL is actually something like
dispatch.fgci?controller=foo&action=bar&id=1
Routes.rb addes the slashes.
On 9/22/06, Gareth Adams
<gareth.adams-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Hi,
>
> url_for has a nice way of using the current ''params''
object to fill in
> default
> parameters in a route. For example,
>
> map.connect '':controller/:action/:id/''
>
> with <%= url_for :action => ''my_action'' %> will
redirect to the current
> controller. All very good.
>
> However, I sometimes want a url_for() which includes current parameters
> which
> aren''t in the route, for example I might want a link to preserve
> ?order=name in
> the query string.
>
> I''ve been using url_for(params.merge({:new_param =>
new_value})), but
> there''s a
> problem with controllers in modules
>
> # params == {:controller => ''sub/controller'', :action
=> ''action''}
> url_for params.merge({:new_param => new_value})
> # ==> /sub/sub/controller/action?new_param=new_value
>
> to fix the problem I have to put
>
> params.merge({:controller =>
"/#{params[:controller]}"}).merge({:new_param
> =>
> new_value})
>
> My question is, is there an easier way to do this? And if not, why is
> params[:controller] not anchored with a ''/'' to start
with?
>
> Gareth
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---