[LRUG] Matching database tables through Ruby

Pratik Naik pratik at thinkwares.com
Tue Aug 14 09:08:06 PDT 2007


I'd personally use http://agilewebdevelopment.com/plugins/acts_as_state_machine

-Pratik

On 8/14/07, Marcus Roberts <marcus at marcusr.org.uk> wrote:
> I'm working on a piece of code at the moment that has raised a
> problem I've seen a couple of times.
> This is for a Rails app, but comes up generally.
>
> I have a tasks table, where a task has a status field, indicating if
> it's "Open", "In progress" or "Closed"
>
> I also have a database table called status, which to keep it simple
> looks like:
>
> 1, "Open"
> 2, "In Progress"
> 3, "Closed"
>
> I use a database table so the status types perhaps can be added to in
> the future through the web interface.
>
> A simplistic approach to setting a task to "In Progress" is to say
>
> Task.status = 2
>
> or to check if a task is closed:
>
> if task.status==3 ...
>
> Using hard coded values like that is an obvious bad thing to do.
>
> Is there a nice pattern for making the link between values in a
> database and the Ruby code?
>
> If I didn't want to change the status types available in the future,
> what's the best way to hard code them into the Ruby itself, assuming
> this use of a database table is the wrong way to do it?
>
> Thanks
>
> Marcus
>
>
>
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>


-- 
http://m.onkey.org



More information about the Chat mailing list