I’m quite new to Ruby/Rails thing, so please be patient with me
-------- (skip to next -------- if you want to quickly see the
I am learning by creating something like timetable application (like
in school). There are days 1-5 and lessons 1-8.
I have to db tables, subjects, which is the list of subjects, and
subject_lessons, which is assocation of a subject to a particular day
and lesson. It’s a one-to-many relationship, because one subject can
be assigned to more lessons, but on one lesson there could be only one
Now I’ve been playing with select and collection_select, and I found
out, that I can set value by specifying an object and a method. Pretty
cool for static tables, but this is kinda more dynamic. I have loops
to generate a table, and each lesson should have a select box.
So I created a new class, called timetable, and I would like to create
methods like 1_1, 1_1=, 1_2, 1_2= - getters and setters for each
lesson of each day.
By the way, the timetable has a result set from active record as a
private variable, and I turned it into hash, so that I could access it
by @subject_lessons[‘1_1’] etc.
In PHP, there’s a __call method, which would do something like this:
function __call($function, $arguments)
$this->subject_lessons[$function] = $arguments;
So I need something like this in Ruby. Hope someone will help me
Thank you guys very much!
By the way Ruby is beautiful but it is pretty different from PHP (I’m
working in PHP for like 4 years, and in Ruby for like few days)