Have you ever considered reading the Rails source code? Not everything,
Actually, I usually do–I come to rails after several years of coding
in ruby, so I find it interesting how things are done, and there’s
much to be learned from how rails uses ruby. I’m just having this
really hard time navigating the docs.
If you’re using the ones at api.rubyonrails.org, then of course you’re
having trouble navigating them. Try http://www.railsbrain.com or
http://www.railsapi.com – same info, but more easily searchable.
Don’t get me wrong–I think the
docs are great, and I can’t imagine how such a feature rich
environment could be doc’d differently–it’s just very difficult for
me the newbie (not necessarily any newbie, probably just me) to figure
out how to use them well.
Read docs for whole classes, not just isolated methods. That will help.
Read class preambles. There’s a lot of info in there, including
dynamically faked methods that won’t show up in the method list (like AR
I’m still waiting for that lightbulb moment
(like the one that happened with the C++ STL so long ago) where I know
where to look and how to use what I find.
Look in the same class as a similar method you already used. Chances
are what you want will be there.
Oddly, I never needed it
with ruby itself–I just sort of used the docs naturally from day 1.
Ruby and Rails are more than just collections of methods. Read the
class preambles (Rails) and the pickaxe book (Ruby), and make sure you
understand the way the language and framework work. Also take note of
the :options that Rails likes to use.
Case in point: last night I was trying to figure out how to implement
a drop-down list for fields from a single db. I’m using
collection_select elsewhere in the code to reference 1 db linked to
another, but I wanted to pull an id from a single db in a drop down
list. I finally gave up after several hours of reading the docs,
searching and trying different things. I could have built an array
from the db, then used another _for_select method I suppose, but I
just know a better way exists, and so I put it on the back burner as
I’ve recently been scolded for posting too much here.
If you’re referring to my scolding, then I think you misunderstood me.
By all means, ask intelligent questions as much as you like! – once
you’ve read the docs carefully. If you’ve done that (as in this case)
and still not found the answer, please do post here.
Anyway, I’m likely just dense as a brick.
Well, you said it…
Thanks, though, to everyone
who have patiently answered my questions with really nice, long
replies and sample code–they’ve been priceless. I couldn’t have
built this project (obviously my first rails one) without your help.
You’re most welcome.