Last active
April 2, 2025 02:48
-
-
Save tabishiqbal/32fe6c17f74c7da09c24d33feee77e26 to your computer and use it in GitHub Desktop.
Revisions
-
tabishiqbal revised this gist
Oct 17, 2023 . No changes.There are no files selected for viewing
-
tabishiqbal revised this gist
Oct 17, 2023 . 4 changed files with 15 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ <%= form_with(model: product) do |form| %> <div> <%= form.label :name %> <%= form.text_field :name, class: "input" %> </div> <div> <%= form.label :categories %> <%= form.collection_select :category_ids, Category.all, :id, :name, {}, {multiple: true, id: 'category-select', class: "dropdown"} %> </div> <%= form.submit "Save product", class: "btn-primary" %> <% 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ class Product < ApplicationRecord has_many :product_categories has_many :categories, through: :product_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 charactersOriginal file line number Diff line number Diff line change @@ -16,8 +16,7 @@ def create private def product_params params.require(:product).permit(:name, category_ids: []) 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,10 @@ import TomSelect from "tom-select" document.addEventListener("turbo:load", () => { // Initializes a tom-select dropdown for elements with the 'category-select' ID. // The 'remove_button' plugin adds functionality to remove selected items. new TomSelect('#category-select', { plugins: ["remove_button"], }); -
tabishiqbal revised this gist
Aug 12, 2023 . No changes.There are no files selected for viewing
-
tabishiqbal revised this gist
Aug 12, 2023 . 2 changed files with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,12 @@ <%= form_with(model: [:admin, product]) do |form| %> <%# other form fields %> <div class="mt-6"> <%= form.label :categories %> <%= form.collection_select :category_ids, Category.all, :id, :name, {}, {multiple: true, id: 'category-select', class: "mt-1"} %> </div> <%= form.button "SAVE", data: { disable_with: "Processing..." }, class: "inline-flex items-center rounded-md bg-gray-900 px-6 py-2 text-xs tracking-wide text-gray-100 shadow-sm hover:bg-gray-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600" %> <% 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 charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ def create private def product_params params.require(:product).permit(....., category_ids: []) end -
tabishiqbal created this gist
Jul 31, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ <%= form_with(model: [:admin, product]) do |form| %> <div class="mt-6"> <%= form.label :categories %> <%= form.collection_select :category_ids, Category.all, :id, :name, {}, {multiple: true, id: 'category-select', class: "mt-1"} %> </div> ..... <% 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ class Product < ApplicationRecord has_many :product_categories has_many :categories, through: :product_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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ class ProductsController < ApplicationController def create @product = Product.new(product_params) respond_to do |format| if @product.save format.html { redirect_to admin_product_url(@product), notice: "Product was successfully created." } format.json { render :show, status: :created, location: @product } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @product.errors, status: :unprocessable_entity } end end end private def product_params params.require(:product).permit(....., category_ids: []) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ import TomSelect from "tom-select" document.addEventListener("turbo:load", () => { new TomSelect('#category-select', { plugins: ["remove_button"], }); })