Ruby Forum JRuby > Rails 2.0 & helpers

Posted by John Woodward (Guest)
on 08.05.2008 18:32
(Received via mailing list)
I don't know if this is a JRuby specific issue, or just a general issue 
with
Rails.

I have 2 controllers, say, "A", and "B". Associated with this, then, are 
2
views, as well as 2 helpers.

Is it possible to have a helper method in a_helper.rb and in 
b_helper.rb? A
little more specifically, I have a helper method to display a chart 
drawn
with JFreeChart; the helper method really just turns around and invokes 
a
method on the controller. The implementation of the methods is a little 
bit
different (given different controllers), but the intent was the same, so 
I
named the helper method the same in both helpers. I would have thought 
that,
while the "A" view was being rendered, only the "A" helper was 
available,
but the error message I'm getting indicates that the helper from "B" is
being invoked (I can easily tell because the B helper takes a parameter
while the A helper does not).

I've done some digging on the web, and found some indication of helpers
sharing a namespace, but nothing specifically addressing this issue.

Thanks!

j
Posted by Phillip Gawlowski (Guest)
on 08.05.2008 19:45
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Woodward wrote:
| I don't know if this is a JRuby specific issue, or just a general
issue with
| Rails.

It's a Rails issue. ;)
So, you might want to ask there for better results.


| I have 2 controllers, say, "A", and "B". Associated with this, then, are 2
| views, as well as 2 helpers.
|
| Is it possible to have a helper method in a_helper.rb and in
b_helper.rb? A
| little more specifically, I have a helper method to display a chart drawn
| with JFreeChart; the helper method really just turns around and invokes a
| method on the controller. The implementation of the methods is a
little bit
| different (given different controllers), but the intent was the same, so I
| named the helper method the same in both helpers. I would have thought
that,
| while the "A" view was being rendered, only the "A" helper was available,
| but the error message I'm getting indicates that the helper from "B" is
| being invoked (I can easily tell because the B helper takes a parameter
| while the A helper does not).

Refactor the helper into an application helper, and pass it an
(additional) parameter signifying which controller called it, so you get
the right code-variant?

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com

At the core of all well-founded belief, lies belief that is unfounded.
~ -- Ludwig Wittgenstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgjPAwACgkQbtAgaoJTgL/fHACgkv3dXvrWYmTsYO8vY4Qp6sLG
EckAn3Be4MavZ/vQQqy37m+Jvizf36wJ
=Sp0u
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email