Last active
March 18, 2020 02:23
-
-
Save staycreativedesign/d508e1b5b0ecd3367e0d9d7c364de358 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| %h1 | |
| hello | |
| - detail_subs.each do |sub| | |
| .form-group | |
| = sub.title | |
| = binding.pry | |
| = select_tag(:details, options_for_select(sub.details.pluck('title', 'id'), entry.detail_ids), multiple: true, class: 'chosen-select form-control') | |
| :javascript | |
| $(function() { | |
| $(".chosen-select").chosen(); | |
| }) |
This file contains hidden or 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
| .form-group | |
| = f.label :detail_category_ids, 'Select Amenities' | |
| = f.select(:detail_category_ids, options_from_collection_for_select(DetailCategory.all, 'id', 'title', f.object.detail_categories), {}, class: 'chosen-select-detail form-control') | |
| .form-group | |
| #detail_subs | |
| :javascript | |
| $(".chosen-select-detail").chosen().change(function(e){ | |
| var detail_category_id = e.target.value | |
| $.get( | |
| '/admin/entries/#{ @entry.slug }/' + detail_category_id + '/detail_subs', | |
| {}, | |
| function(data){ | |
| console.log(data) | |
| }, 'script') | |
| }); |
This file contains hidden or 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
| class Detail < ApplicationRecord | |
| belongs_to :detail_sub | |
| has_many :entry_details | |
| has_many :entries, through: :entry_details | |
| end |
This file contains hidden or 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
| class DetailCategory < ApplicationRecord | |
| has_many :entry_detail_categories | |
| has_many :entries, through: :entry_detail_categories | |
| has_many :detail_subs | |
| end |
This file contains hidden or 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
| class DetailSub < ApplicationRecord | |
| belongs_to :detail_category | |
| has_many :details | |
| end |
This file contains hidden or 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
| class Admin::DetailSubsController < Admin::PagesController | |
| def index | |
| @entry = Entry.friendly.find(params[:entry_id]) | |
| detail_category = DetailCategory.find params[:detail_category_id] | |
| @detail_subs = detail_category.detail_subs | |
| respond_to do |format| | |
| format.js { render layout: false } | |
| end | |
| end | |
| end |
This file contains hidden or 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
| def entry_params | |
| params.require(:entry).permit(:title, :subtitle, :of_type, :intro, :content, | |
| :promo, :author, :address, :city, :state, :zipcode, | |
| :lat, :long, :directions, :website, :email, :synonyms, | |
| :facebook, :instagram, :twitter, :pinterest, :details, | |
| :meta_description, :meta_title, :meta_keywords, | |
| :facility, :group, :internet, :room, :room_amenities, | |
| :discounts, :slug, :type_id, :lake_assn, | |
| :featured_image, :is_featured, images: [], | |
| phone_numbers_attributes: [:id, :label, :number, :_destroy], | |
| videos_attributes: [:id, :url, :_destroy], | |
| hours_attributes: [:id, :title, :label_1, :label_2, :_destroy], | |
| prices_attributes: [:id, :label, :price, :_destroy], | |
| entry_detail_ids: [], related_entry_ids: [], | |
| detail_category_ids: [], topic_ids: [], | |
| documents_attributes: [:id, :position, :title], | |
| ) | |
| end |
This file contains hidden or 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
| class Entry < ApplicationRecord | |
| ... | |
| has_many :entry_details | |
| has_many :details, through: :entry_details | |
| has_many :entry_detail_categories | |
| has_many :detail_categories, through: :entry_detail_categories | |
| ... | |
| end |
This file contains hidden or 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
| class EntryDetail < ApplicationRecord | |
| belongs_to :entry | |
| belongs_to :detail | |
| end |
This file contains hidden or 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
| class EntryDetailCategory < ApplicationRecord | |
| belongs_to :entry | |
| belongs_to :detail_category | |
| end |
This file contains hidden or 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
| :plain | |
| $('#detail_subs').html("#{j render(partial: 'admin/entries/detail_subs', locals: {detail_subs: @detail_subs, entry: @entry})}") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I submit I check for
EntryDetailCategory(id: integer, entry_id: integer, detail_category_id: integer, created_at: datetime, updated_at: datetime)
[9] pry(#<#Class:0x00007ffc8848dbb8>)> EntryDetailCategory.all
CACHE EntryDetailCategory Load (0.0ms) SELECT "entry_detail_categories".* FROM "entry_detail_categories"
↳ app/views/admin/entries/_form.haml:76
=> []
[10] pry(#<#Class:0x00007ffc8848dbb8>)>