cocoon-gem

Update multiple checkboxes on association model through nested attributes with Cocoon gem in Rails

拟墨画扇 提交于 2021-02-10 06:43:47
问题 I found this answer here which should be able to solve my problem but turns out that answer is for a one to many association. Btw, i'm using Rails 5.2 In my many to many, I have a Task model which has_many test_methods through tasks_test_methods where tasks_test_methods is a join table. class Task < ApplicationRecord has_many :tasks_test_methods, inverse_of: :task, :dependent => :destroy has_many :test_methods, :through => :tasks_test_methods accepts_nested_attributes_for :tasks_test_methods,

ActiveAdmin has_many form not saved if parent model is new and is NOT NULL in child model

十年热恋 提交于 2021-02-07 18:32:36
问题 I have two models, Room and Student . Room has_many Student s. Student belongs_to Room . I got an error Room can't be blank when I try to add Student to Room during creating a new Room. My guess is that, upon submission, child object (student) is saved before parent object (room) is saved. Is there a way to bypass the order without remove the NOT NULL setting on room_id? Or my guess is wrong? Or even worse, I am doing it wrong? # app/models/room.rb class Room < ActiveRecord::Base validates

How to create a copy of item added in cocoon nsted form rails?

非 Y 不嫁゛ 提交于 2021-01-29 22:03:34
问题 Im using cocoon to add "victimas" in my form. I would like to have a new button that allows to copy a "victima" added. I think, i should to call the method used to add association passing de fields form data filled. suggestions?. View: <%= link_to_add_association 'Añadir Víctima', f, :victima, { partial: 'sivel2_gen/casos/victima_campos', class: 'btn-primary', "data-ajax" => File.join( Rails.configuration.relative_url_root, "victimas/nuevo" ), "data-ajaxdata" => "caso_id" } %> 来源: https:/

Ruby on rails cocoon gem - unable to capture callback events

隐身守侯 提交于 2020-01-24 21:35:08
问题 Hi I am currently using the cocoon gem for my rails app and it seems to be working fine since I was able to add and remove the nested associations in my form. However, when I try to console log the callbacks (e.g. "cocoon:after-insert"), there is no console log fired on the console. What could be the reason for this and how can i capture the callback event in my console? I have the gem remotipart bundled in my app too, if this would offer any clue as to why I have been unable to capture the

Cocoon Item field not posting values to database

依然范特西╮ 提交于 2020-01-15 10:18:11
问题 I have a genearted lineItem field using Cocoon gem, am having issues trying to save the line items field values,and when I inspect the elements the add_item button wasn't triggering a unique ID for each new field generated. class InvoicesController < ApplicationController before_action :set_invoice,:set_line_item, only: [:show, :edit, :update, :destroy] def index @invoices = Invoice.all end def show end def new @invoice = Invoice.new @invoice.line_items.build end def edit end def create

No errors and no output for rails cocoon gem

痞子三分冷 提交于 2020-01-11 10:31:08
问题 I am working on a dynamically nested form using the cocoon gem. I have two models class CrossTable < ActiveRecord::Base attr_accessible :title, :table_name, :database, :folder_label_id, :foreign_fields_attributes belongs_to :folder_label has_many :foreign_fields accepts_nested_attributes_for :foreign_fields validates :title, :table_name, :database, :folder_label_id, presence: true end class ForeignField < ActiveRecord::Base attr_accessible :cross_table_id, :column_name, :description belongs

Javascript: Using a method from model in javascript code

╄→гoц情女王★ 提交于 2020-01-07 05:09:10
问题 I am trying to set up users on an asset, and I am running into the problem of not being sure how to pass my max_users method from asset.rb to my JS code. I am trying to use the max_users method with the Cocoon gem to have the "Add Another" button disappears when it reached the specified max_users allowed for that asset. Hardware will always be set with a max_user of 1, while software will never have a max_user value. Max_users works as it should, as does profile_type. The JS works as it is,

Validating uniqueness of nested data. Using cocoon gem

痴心易碎 提交于 2020-01-06 20:05:38
问题 I currently have a Client model that has_many pricings. Pricings table: create_table "pricings", force: true do |t| t.integer "product_id" t.integer "client_id" t.decimal "unit_price" t.datetime "created_at" t.datetime "updated_at" end Pricings model: class Pricing < ActiveRecord::Base belongs_to :client belongs_to :product validates :unit_price, presence: true end Client model: class Client < ActiveRecord::Base has_many :deliveries has_many :collections has_many :pricings accepts_nested

Validating uniqueness of nested data. Using cocoon gem

淺唱寂寞╮ 提交于 2020-01-06 20:01:52
问题 I currently have a Client model that has_many pricings. Pricings table: create_table "pricings", force: true do |t| t.integer "product_id" t.integer "client_id" t.decimal "unit_price" t.datetime "created_at" t.datetime "updated_at" end Pricings model: class Pricing < ActiveRecord::Base belongs_to :client belongs_to :product validates :unit_price, presence: true end Client model: class Client < ActiveRecord::Base has_many :deliveries has_many :collections has_many :pricings accepts_nested

Ruby on Rails 4: Missing form field after commit - error is “Unpermitted parameter: ingredients_attributes”

二次信任 提交于 2020-01-06 13:11:51
问题 Question: I'm working with cocoon gemfile & following the ERB style of it without haml/slim. I have my github here - The branch I'm working on is "cmodel" - Link. The error is: Unpermitted parameter: ingredient_attributes Really what I don't understand is just about everything about the models. I get pluralization is a thing. I get that strong parameters is a thing. My understanding to implement them is a bit fuzzy. I've found the rails guides & edge rails guides too simple for the expanded