cocoon-gem

Cocoon add association, how to limit number of associations

梦想与她 提交于 2019-12-18 04:16:31
问题 I am creating a system that stores cards using Ruby/Rails/HAML - In this case there is a Card class that has many Colours (this is also a class). When creating and editing a card I am using the Cocoon gem to allow me to dynamically add colour associations. The problem I am having is that in the Card model, a card is limited to having a maximum of 5 colours. Yet the interface allows adding of unlimited colours resulting in an error. Is there a way in Cocoon to limit the number of associations

NoMethodError in Index: How to Define the Nested Attributes?

99封情书 提交于 2019-12-13 08:24:37
问题 NoMethodError in Quantifieds#index undefined method `date_value' for #Quantified:0x007ff3fe7d6c08 How do I define date_value & result_value so it works in the quantifieds index? <!-- Default bootstrap panel contents --> <div id="values" class="panel panel-default"> <div class="panel-heading"><h4><b>AVERAGE</b></h4></div> <!-- Table --> <table> <% @averaged_quantifieds.each do |averaged| %> <% if averaged.user == current_user %> <th class="value"> <%= link_to edit_quantified_path(averaged) do

cocoon gem attributes not saving when creating new recipe

流过昼夜 提交于 2019-12-13 02:49:54
问题 In week 3 of mackenziechild-recipe_box, I am experiencing some issues with Cocoon. I have devise installed, as well, and my ingredients and directions attributes are not being saved when I create a new Recipe . But when I update an existing Recipe , everything is fine. The error message is: Ingredients recipe must exist, directions recipe must exist What am I doing wrong? I am using rails 5 app/models/recipe.rb class Recipe < ApplicationRecord validates :title, :description, :image, presence:

Rails 4 - nested attributes with Cocoon gem

不羁岁月 提交于 2019-12-13 01:34:54
问题 I'm trying to make an app with Rails 4. I'm using Cocoon gem for nested forms with simple form. I have a qualifications model, nested in a profile model. The associations are: Qualifications belongs_to :profile Profile has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true In my profile form, I incorporate the qualifications attributes with: <%= f.simple_fields_for :qualifications do |f| %> <%= render 'qualifications/qualification

Rails deletes record on edit and not submit

…衆ロ難τιáo~ 提交于 2019-12-13 01:24:38
问题 Having the following associations: Workout has_many workout_sets through ... workout_set has_many workout_steps through ... When editing an object I'm experiencing the following issue: 1) go to /model/:id/edit 2) checking the db, once the page loads the top level attributes (the non-nested ones) are deleted from the db once the page loads, but the select marks as selected the correct values, as if in the moment of the load the data was correct. 3) leaving the page without saving (returning to

Rails - Cocoon gem - Nested Forms

廉价感情. 提交于 2019-12-12 18:38:30
问题 I am trying to make an app with Rails 4. I use simple form gem for forms and am trying to use Cocoon gem for nested elements of the forms. I asked this question, which explains what I'm trying to achieve in more detail: Rails - Multiple entries for a single attribute I have a profile model and a qualifications model. The associations are: profile.rb has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true qualification.rb belongs_to

Rails 5.2 Active Storage with Cocoon forms

白昼怎懂夜的黑 提交于 2019-12-12 16:33:24
问题 I want to save some images to a model using a dynamic cocoon form with Active Storage to handle the files. I have a farmer class that has many apples, the farmer can add multiple images for each of the different kinds of apples through the farmer form. class Farmer < ActiveRecord::Base has_many :apples, inverse_of: :farmer accepts_nested_attributes_for :apples, allow_destroy: true, reject_if: :all_blank end class Apple < ActiveRecord::Base has_many_attached :apple_images end Inside the Farmer

How to get input value with Cocoon and Javascript?

两盒软妹~` 提交于 2019-12-12 05:01:57
问题 I try to implement a simple order management system where users can create new commands and add two types of product to them. When a user select a product and enter a quantity, the total price is dynamically calculated and displayed in the last field. For adding a new product line to the order, I use the gem Cocoon. My problem is that I'm not able to calculate the total price for every new product added with Cocoon. Every time I enter a quantity, I get the total price from the first line. Is

Rails - Parameters not being saved when using nested forms in Cocoon

我的梦境 提交于 2019-12-12 01:56:13
问题 I've followed Cocoon's instructions for creating a nested form for a has_many association but there's one thing that I can't seem to figure out. I'm able to add an existing genre to my project but when it comes to creating a completely new one the parameters for my genres aren't being permitted. When I refer to my rails console to debug the issue this is the message I receive upon update: Unpermitted parameters: genre_attributes What's strange is I've permitted both my join table genreships

Cocoon Gem: undefined method `new_record?' for nil:NilClass on link_to_remove_association

天涯浪子 提交于 2019-12-11 20:19:59
问题 I am trying to build a nested form with the Cocoon Gem. however i am getting the error as shown below. I found another answered question here that Rails Cocoon Gem: Undefined Method 'new_record?' on link_to_remove_association with Wicked. However the only answer has already been ruled out as you can see from my model code. Error ActionView::Template::Error (undefined method `new_record?' for nil:NilClass): 1: <div class="nested-fields"> 2: <%=f.input :name%> 3: <%= link_to_remove_association