-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Nov 10, 2005, at 12:05 PM, Francois Beausoleil wrote:> While reading a recent thread on the Rails ML, by Mark Van Holstyn,
> entitled "render partial and passing in the object" [1], I asked
> myself if we could do better. I wrote a bit about it on my blog
> "Rails Helpers and Instance Variables" [2].
>
> To summarize, here''s what Rails does in the form helpers:
>
> def url_for_file_column(object_name, method, suffix=nil)
> object = instance_variable_get("@#{object_name.to_s}")
> ...
> end
>
> Here''s what it could do instead:
>
> def url_for_file_column(object_name, method, suffix=nil)
> object = case object_name
> when String, Symbol
> instance_variable_get("@#{object_name.to_s}")
> else
> object_name
> end
> ...
> end
>
> Of course, we can''t require everyone to type all of this code, it
> wouldn''t be very DRY. We should instead have some kind of helper
for
> helpers that would do it. Would a patch along those lines be
> acceptable ?
>
> It would mean changing a significant amount of code, and 1.0 being so
> close, I''m not sure the patch would be accepted outright.
See InstanceTag#object in actionpack/lib/action_view/helpers/
form_helper.rb
I''d *love* to pass an object directly to the form helper rather than
the object''s variable name, but we need the name and Ruby
can''t tell
it to us. So instead we start with the name and deduce the variable.
We can update InstanceTag#object to look for local variables as well
as instance variables (a conundrum that is especially painful when
rendering nested partials) but we''ve held off in order to maintain
compatibility with 1.0.
Best,
jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)
iD8DBQFDc6veAQHALep9HFYRAuzQAJ9Evkx5QibCXqNMaB+PCavkEDnqPQCgibNn
35R7FXx+C0Y4XTAkSKhW4gY=kFrk
-----END PGP SIGNATURE-----