Hi, this is a question and possibly also a suggestion for vIII based on trying and (so far) failing to learn rails from books (and lots of them).
Something I’ve really wanted but not yet found is a clear explanation of instance variables in Rails - something that will help me visualise the some of their most common functions in Rails applications and the basic essentials on how they work, so that I can start experimenting with them confidently.
To clarify, not an explanation of instance variables in Ruby, but an explanation of instance variables in Rails.
That might sound stupid, since obviously they’re the same thing. There are differences though. Partly this difference is from the in-built Rails features such as changes to where they can be accessed from and pre-packaged methods that use them. For some reason, even in Rails books, descriptions of instance variables don’t mention these. In addition, it’s from differences in convention and the kinds of functions they’re normally used for - this is particularly important for us newbies trying to visualise what things do enough to know how to start experimenting.
To give one example, I’m finding it very hard to square what I see in example Rails applications of instance variables being used to carry and manipulate arrays of data off a table with what I read about Ruby’s instance variables being like attributes of objects intended mainly for internal storage. For example, in a very standard use of find_all to get the contents of a table up through a controller into the view, are the table contents put into a single array in a single instance variable which acts as a single object, or does it creates a stack of instances each with one array to which the instance variable is the class, or does it create a stack of instances of the controller class each with one instance of the instance variable and one array…
Clearly I’ve understood something very badly wrong, and from browsing forums and blogs I’m sure I’m not alone. Descriptions of instance variables in pure ruby have just confused me further. When I’m more comfortable with the basics, pure ruby will be great to broaden my horizons as to the range of things it’s capable of, but right now they’re confusing. I feel like I need to understand the standard, basic ways instance variables are used and work in rails first, and then make it more abstract when I’ve got a firm handle on the basics, if that makes sense.
Is this just me? And can anyone see where I’m going wrong? All help appreciated, thanks, and apologies for any embarrassing gaps in my knowledge.