Skip to content

Instantly share code, notes, and snippets.

@allenwlee
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save allenwlee/c35f3cc4d23a3a61b9bd to your computer and use it in GitHub Desktop.

Select an option

Save allenwlee/c35f3cc4d23a3a61b9bd to your computer and use it in GitHub Desktop.
def user_params
params.fetch(:user, {}).permit(:id, :roduction_media_users_attributes: [:id, :user_id, {production_medium_id: []}])
end
def project_params
params.fetch(:project, {}).permit(:id, genres_projects_attributes: [:id, :project_id, {genre_id: []}])
end
class User < ActiveRecord::Base
has_many :production_media, through: :production_media_users
has_many :production_media_users
accepts_nested_attributes_for :production_media_users
end
class ProductionMedium < ActiveRecord::Base
has_many :users, through: :production_media_users
has_many :production_media_users
end
class Project < ActiveRecord::Base
has_many :genres, through: :genres_projects
has_many :genres_projects
accepts_nested_attributes_for :genres_projects
end
class Genre < ActiveRecord::Base
has_many :projects, through: :genres_projects
has_many :genres_projects
end
<%= select_tag 'user[production_media_users_attributes][][production_medium_id][]', options_for_select(ProductionMedium.order(:id).collect{|g| [g.name, g.id]}), { include_hidden: true, multiple: true, required: true, placeholder: 'Choose One or More', class: 'form-control menu-select2'} %>
<%= select_tag 'project[genres_projects_attributes][][genre_id][]', options_for_select(Genre.order(:id).collect{|g| [g.name, g.id]}), { include_hidden: true, multiple: true, required: true, placeholder: 'Choose One or More', class: 'form-control menu-select2'} %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment