Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lengshuiyulangcn/a1006143c34e0c9bef13 to your computer and use it in GitHub Desktop.
Save lengshuiyulangcn/a1006143c34e0c9bef13 to your computer and use it in GitHub Desktop.
rails4 strong parameters, has_and_belongs_to_many relation, mongoid
#model
class Band
include Mongoid::Document
has_and_belongs_to_many :tags
end
class Tag
include Mongoid::Document
field :name, type: String
has_and_belongs_to_many :bands
end
#controller
def band_params
params.require(:band).permit(:id,tags_attributes=>[:id,:name,:band_ids=>[]])
end
##create
Band.new(band_params).save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment