logo       

Re: R() in controllers: msg#00037

lang.ruby.camping.general

Subject: Re: R() in controllers

Paul van Tilburg wrote:
> Here I use R(Foo, bar) in views to link to controller foo, this correctly
> creates a /test/foo/bar link. However, when I use R() in some controller,
> for example:
>
> headers['Refresh'] = "60; url=#{R(Foo, bar)}"
>
> The generated link is /foo/bar, which obviously links to something
> non-existant. Can somebody affirm that R() in controllers do not
> work correctly?

I don't think it's working incorrectly -- just a little unintuitively.
In short, R() only prepends the app root (i.e. '/test') to the
generated URL when called from within a View -- not Controllers.

This can be worked around by using the "slash method"[1]:

self / R(Foo, Bar) #=> '/test/foo/bar'

See the Camping docs for the R() helper method[2], and the "Using R in
the View" section in particular, for a fuller explanation.

--
Adam

[1] http://camping.rubyforge.org/classes/Camping/Helpers.html#M000016
[2] http://camping.rubyforge.org/classes/Camping/Helpers.html#M000014


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise