Coding Guidelines: Instance variables in views

Matt Wagner matt.wagner at redhat.com
Thu Aug 16 15:05:35 UTC 2012


Hi folks,

I've noticed that we've been objecting to patches using instance
variables to pass information to views, so I went to see our coding
guidelines page[1] to read about why.

It makes very clear that it's bad, but it doesn't really explain the
right way. I'd hoped that the Coding Guidelines page would be more of a
guide on how to do things the right way.

I've really only found one blog post[2] that addresses the issue, and it
doesn't really give a great example. It still uses an instance variable
in the controller, but inside of a view it passes it as a local
variable. It's more specific, sure, but it's not abundantly clear how
that actually makes anything better, or why an instance variable from
the controller to the view is okay but a view to a partial is not okay.

Can someone with a more concrete understanding of the right way update
the wiki page, or send me some pointers so I can do so? I'd love for the
page to show the right way, maybe an example of rewriting the "bad way"
into the right way, rather than just giving a stern warning that it's
bad.

-- Matt

[1]
https://www.aeolusproject.org/redmine/projects/aeolus/wiki/Coding_Guidelines

[2]
http://rails-bestpractices.com/posts/27-replace-instance-variable-with-local-variable



More information about the aeolus-devel mailing list