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.

Revisions

  1. allenwlee revised this gist Jul 10, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion output
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    {"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", "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"}
  2. allenwlee revised this gist Jul 10, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions output
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {"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"}
  3. allenwlee revised this gist Jul 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion controllers.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    def user_params
    params.fetch(:user, {}).permit(:id, :roduction_media_users_attributes: [:id, :user_id, {production_medium_id: []}])
    params.fetch(:user, {}).permit(:id, :production_media_users_attributes: [:id, :user_id, {production_medium_id: []}])
    end

    def project_params
  4. allenwlee revised this gist Jul 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion views.erb.html
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    <%= 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, class: 'form-control'} %>
    <%= 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'} %>
  5. allenwlee revised this gist Jul 10, 2014. 2 changed files with 26 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions models.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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

    3 changes: 3 additions & 0 deletions views.erb.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <%= 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, class: 'form-control'} %>

    <%= 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'} %>
  6. allenwlee created this gist Jul 10, 2014.
    7 changes: 7 additions & 0 deletions controllers.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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