I’ve spent some time converting my website from php to RoR, and so far,
I’m loving every bit of Rails. However, I’ve stumbled across a problem.
On my old page, I’ve had a random quote display at a specific location,
and I’d like to replicate this with RoR. Basically, I thought I would be
able to add all quotes into a specific table in the database, and
somehow have a global variable stored in
/app/controllers/application.rb, since I want it to be accessed from all
different controllers. So far, I’ve managed to get this to work:
$quote = ““An witty saying proves nothing”- Voltaire”
in application.rb and
<%= $quote %>
in my layout file, which I gather is a step on the way. From here on,
however, I’ve had no luck. I’ve tried setting the variable to many
different things, but it doesn’t seem to want to take anything but pure
text (as displayed above). I’ve tried searching for this in the docs and
the wiki, but documentation on (any kind of) variables is amazingly
noticable in its absence.
Basically, I would be very happy if someone could point me in the right
direction to get the variable to somehow draw information out of the
database. If given that much information, I’m sure I could find a way to
randomise the quotes myself, but if someone wants to tell me how to do
that as well, I’d be even happier.
Thanks in advance,