rubyonrailsin

A Ruby and Rails talk

Wednesday, March 10, 2010


Re: [Rails] Using store values from drop down list

by rubyonrailsin 0 comments



Share this post:
Design Float
StumbleUpon
Reddit

On 10 March 2010 14:41, Andy Jeffries <andyjeffries@gmail.com> wrote:
> I would change that as follows:
> CLUB_TYPES = {
>   "pub" => "Public",
>   "vil" => "Village",
>   "pvt" => "Private"
> }
>

...as long as there's no need for clubtypes to be displayed in any
particular order (arrays are returned in order, hashs aren't
necessarily)


For the minuscule amount of extra effort involved, create a model for
club types, seed it, and give it a "position" column if you want to
manage the order (or just put an :order clause on your default
finder).

Then use ClubType.all or named scopes for more functionality ...

Your clubs can change their club_type text column into a club_type_id
integer and add a belongs_to relationship, allowing you to do nice
easy queries, leverage Rails' functionality, and get rid of those
"magic" array/hash variables.

Sometimes things that seem like shortcuts (like using an array for
some "static" data) can quickly turn into dead ends. The framework
does all the hard work for you, so you might as well use it.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive