Last active
August 29, 2015 14:15
-
-
Save lengshuiyulangcn/a1006143c34e0c9bef13 to your computer and use it in GitHub Desktop.
rails4 strong parameters, has_and_belongs_to_many relation, mongoid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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