[LRUG] Proffer and introducing constraints to Rails

Tom Stuart tom at therye.org
Mon Apr 2 08:17:05 PDT 2012


Also, I can't think of many situations in which one sets an instance variable in a Rails controller (with the exception of setting up an object in a before_filter for use in an action - see conversations passim) for any reason other than exposing it to the view. I'm not convinced that changing "@post = foo" to some explicit means of passing the data to the view is a huge inconvenience.

But I may have forgotten myriad use cases for instance variables in Rails controllers, in which case please forgive and ignore this post.

Cheers,

Tom

On 2 Apr 2012, at 16:05, James Hunt wrote:

> How much more convenient is it though? How much time do you really save by having instance variables by default? It's interesting to think about this the other way: if Rails had never exposed instance variables by default, would you even miss it? Would you have written a gem to add the functionality? How would you justify it?
> 
> In the scheme of all the things you have to do to get a Rails app working, not having instance variables in views seems like a really small thing. And if you were reaaaaallly desperate, you could do:
> 
> <% @post = post %>
> 
> at the top of your view and you're back in business! The only difference here is that before you do something like the above, you have to actually think about what you're doing and why before you do it. It's a convention: break it if you want, but know why you're doing it and what it may cost you later on.
> 
> James
> 
> On Mon, Apr 2, 2012 at 2:43 PM, Ed James (Alt) <ed.james.spam at gmail.com> wrote:
> Further to Andy's comment, we also need to remember that many Rails apps start off as prototypes. The prototypes that work quite often make it to a version release, which doesn't always allow for much refactoring. Stuff has to get done quickly and this is what makes Andy's "instant access" valuable. It can also be quite cumbersome to have too many strict rules (and even tests!) when the requirements are in a constant state of flux, which is common in early development stages.
> 
> -- 
> Ed James
> Sent with Sparrow
> 
> On Monday, 2 April 2012 at 11:42, Andrew Stewart wrote:
> 
>> 
>> On 2 Apr 2012, at 12:20, Viktor Tron wrote:
>>> I don't know who came up with this pattern in rails in the first place, it violates everything you ever wanted objects and instance variables to mean.
>> 
>> True, but you have to admit it's tremendously convenient ;)
>> 
>> I know it's heretical to say so but I like being able to access instance variables as if by magic in my views. I came to Rails from J2EE / JSP / servlets where accessing controller data in views was outstandingly tedious. I know Rails' approach violates encapsulation and so on...but I like it.
>> 
>> Cheers,
>> 
>> Andy Stewart
>> ----
>> http://airbladesoftware.com
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> 
> 
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> 
> 
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120402/497f3130/attachment-0003.html>


More information about the Chat mailing list