Skip to content

Instantly share code, notes, and snippets.

@allenwlee
Last active August 29, 2015 14:03
Show Gist options
  • Save allenwlee/c35f3cc4d23a3a61b9bd to your computer and use it in GitHub Desktop.
Save allenwlee/c35f3cc4d23a3a61b9bd to your computer and use it in GitHub Desktop.
def user_params
params.fetch(:user, {}).permit(:id, :production_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
{"utf8"=>"✓", "_method"=>"patch", "project"=>{"id"=>"1913", "name"=>"Turquoise Girder", "genres_projects_attributes"=>{"genre_id"=>["11"]}, "logline"=>"", "synopsis"=>"", "imdb_link"=>"", "status"=>""}, "commit"=>"Update", "attribute"=>"profile", "controller"=>"projects", "action"=>"attribute_edit"}
{"utf8"=>"✓", "_method"=>"patch", "user"=>{"username"=>"STUDIOCOMPS", "given_name"=>"ALLEN", "family_name"=>"LEE", "production_media_users_attributes"=>[{"production_medium_id"=>["2"]}], "experience1"=>"Lions Gate Entertainment", "experience2"=>"", "education1"=>"Columbia MBA", "education2"=>"UC Berkeley", "linkedin_url"=>"http://www.linkedin.com/in/...", "bio"=>"..."}, "commit"=>"Update Profile", "action"=>"update", "controller"=>"users", "id"=>"91"}
<%= 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