Remco
Remco

Reputation: 683

Rails 3 Relationships

I have a Property model with some basic content like Property Description, Property Title, etc.

The type of the property can be a house, villa, castle, B&B, etc. What is the best way to implement the property type? For example I want to generate top 10 listing of property types X on different pages.

Upvotes: 1

Views: 77

Answers (1)

davidb
davidb

Reputation: 8954

There are two possibilities. If these types are static you can declare a constant in the Model like this:

PROPERTY_TYPES = %w[villa, castle, other]

And add it to the view like this:

<%= f.collection_select :property_type, Model::PROPERTY_TYPES, :to_s, :humanize %>

But if you want something dynamic you should add another Model which contains the different types possible. ANd you should also avoid using the name typeas field name because its used by ActiveRecords.

Upvotes: 1

Related Questions