R
Ryan Williams
I'm a ruby newbie and have what is probably a relatively simple problem
I'm trying to solve (though I'm using rails, this is more a ruby
question). Say that I created a hash:
TASKS = {
"homework" => "Do Your Homework",
"chores" => "Your Have Chores",
"exercise" => "Don't Forget to Exercise"
}
and then I had an Assignment model with:
def self.find_assignments(person)
findall, :conditions => ["person_id = ?", person .id])
end
Which I called in the controller like so:
@current_assignments = Assignment.find_assignments(@person)
So, @current_assignments works fine. Now, the problem. I want to display
the tasks which have NOT yet been assigned (so that they can be assigned
if desired). In the assignments table, I have a column called 'tasks'
which correlates with the keys in the TASKS hash. So I just want to
remove any key=>value pairs from TASKS that match with the 'tasks'
column in @current_assignment and then loop through the resulting new
hash in the view.
I'm at a loss as how best to do this. It must be something so simple
it's eluding me. Any suggestions?
I'm trying to solve (though I'm using rails, this is more a ruby
question). Say that I created a hash:
TASKS = {
"homework" => "Do Your Homework",
"chores" => "Your Have Chores",
"exercise" => "Don't Forget to Exercise"
}
and then I had an Assignment model with:
def self.find_assignments(person)
findall, :conditions => ["person_id = ?", person .id])
end
Which I called in the controller like so:
@current_assignments = Assignment.find_assignments(@person)
So, @current_assignments works fine. Now, the problem. I want to display
the tasks which have NOT yet been assigned (so that they can be assigned
if desired). In the assignments table, I have a column called 'tasks'
which correlates with the keys in the TASKS hash. So I just want to
remove any key=>value pairs from TASKS that match with the 'tasks'
column in @current_assignment and then loop through the resulting new
hash in the view.
I'm at a loss as how best to do this. It must be something so simple
it's eluding me. Any suggestions?