i'm trying to Add Categories to my Rails app, but don't quite know how
to do this.
I have many Pins(Images) and want the user to be able to assign a
category on those Pins. ASSIGN not create, edit, or delete a Category,
just selecting one for their Pin. Meaning that, When a user uploads a
pin, he can choose from a dropdown list a Category.
Then, another user can choose from the Menu a Category, and ONLY the
Pins in this Category will be listed.
i'm trying to Add Categories to my Rails app, but don't quite know how
to do this.
I have many Pins(Images) and want the user to be able to assign a
category on those Pins. ASSIGN not create, edit, or delete a Category,
just selecting one for their Pin. Meaning that, When a user uploads a
pin, he can choose from a dropdown list a Category.
Then, another user can choose from the Menu a Category, and ONLY the
Pins in this Category will be listed.
It sounds as though you are going to limit them to one category per pin.
Simply using that, a given pin will belong to a category, and a category will have many pins. This should tell you the relationship to use. Read the rails guide on relationships for how to set this up.
Since you are not allowing the user to define categories, you will need, as an admin or as part of your app configuration, to fill in the categories you want your users to be able to select from.
This can certainly work, though seems less flexible in the long run as to update categories you have to go into the code base and make the change there, rather than have a configurable set in a table.
But even with this, it's quite possible, but again, you're necessarily hard coding the selection instead of drawing it from a table. In you category navigation, you offer the user the ability to select on of Box, Cover or Poster, and then use gather them in the appropriate controller with pins = Pin.where(:category => params[:category]) for example (depending on how you actually get the user's desired category).