0

I have an image model and want to assign differnt, pre-choosen tags to the images. I don't want to use a plugin.

This is my image model

class Image < ActiveRecord::Base
  attr_accessible :date, :description, :name, :size, :image, :tag
end

Ideally I want to set check boxes with the different tags while creating or editing the image. Let's say the tags are "blue", "red" and "yellow".

Do I have to create a new model for the different tags? At the moment I have in the new.html.haml file

%div.field
  = f.label "Tag"
    %br/
  = f.select :tag, options_for_select(["blue", "red", "yellow"]), {:multiple => true}

But I can only choose one tag and I prefer to do it one checkbox for each tag (easier to correct the choice). Furthermore I'm not sure if I should create a new model with the different tags and create a relationship, e.g. images belongs_to :tag and tag has_many :images

Is there a simple solution for this?

user929062
  • 807
  • 4
  • 12
  • 33

1 Answers1

0

Ok, as for many other problems the solution is Railscasts:

http://railscasts.com/episodes/167-more-on-virtual-attributes

user929062
  • 807
  • 4
  • 12
  • 33