On 14/08/07, <b class="gmail_sendername">Marcus Roberts</b> <<a href="mailto:marcus@marcusr.org.uk">marcus@marcusr.org.uk</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
A simplistic approach to setting a task to "In Progress" is to say<br><br>Task.status = 2<br><br>or to check if a task is closed:<br><br>if task.status==3 ...<br><br>Using hard coded values like that is an obvious bad thing to do.
<br><br>Is there a nice pattern for making the link between values in a<br>database and the Ruby code?</blockquote><div><br>You could use some const_missing trickery on the model, such that
Status::OPEN would result in returning Status.find_by_name('Open'). 
I've certainly seen that in the wild, and we use it in one of our apps here.<br>
</div><br></div>class Status < ActiveRecord::Base<br>  def self.const_missing(name)<br>    if value = self.find_by_name(name.to_s)<br>      self.const_set(name, value)<br>      value<br>    else<br>      super<br>    end
<br>  end<br>end<br>