Reputation: 12650
I have 10 drop-down fields in a "post" form that I want to be controlled by the admin user.
Currently, I have another model called "post fields"
class PostField
include Mongoid::Document
field :family, type: String
field :project, type: String
field :event, type: String
field :testmode, type: String
field :location, type: String
end
I then use these documents to populate each dropdown for a new post.
I have 2 dilemmas:
This is effectively a tagging model, but poorly implemented b/c I'm not sure how to do it.
ie, I want to have a controlled list of locations: ["Upstairs", "Downstairs", "Bathroom"] so users can't just use a text input and say "Restroom" instead. But if an admin wants to change "Bathroom" to "Restroom", I want the posts to update accordingly.
Hope this isn't too complicated.
Upvotes: 4
Views: 108
Reputation: 2243
Not sure to anderstand what you want to do.
With this schema, you should be able to create a "post" with static fields and dynamic fields.
PostField
PostFieldValue
In model
You should create a method to get the value based on post's field.
Improvements
Upvotes: 0
Reputation: 26274
So you want each PostField to be of a certain type, or location? So you want to limit the values that go into :location?
What you have to do is create another model and table called locations, and that will contain a list of locations like Upstairs, Downstairs, Bathroom, etc. It has and id, and a name. In your PostField, you will join to the Locations with has_one :location
, and the database table will have location_id
. Then the admin can change Location.name to anything they want, while all the PostFields will show the updated label. In the view, use postField.location.name
to display the label for that field.
Upvotes: 3