cocoon-gem

Cocoon add association, how to limit number of associations

佐手、 提交于 2019-11-29 07:21:35
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 that can be added to a form, so that this limit is not exceeded? This is the code for a form to add

Rails 3, nested multi-level forms and has_many through

北战南征 提交于 2019-11-28 17:07:24
I'm trying to get it to work but it dosen't! I have class User < ActiveRecord::Base has_many :events, :through => :event_users has_many :event_users accepts_nested_attributes_for :event_users end class Event < ActiveRecord::Base has_many :event_users has_many :users, :through => :event_users accepts_nested_attributes_for :users end class EventUser < ActiveRecord::Base set_table_name :events_users belongs_to :event belongs_to :user accepts_nested_attributes_for :events accepts_nested_attributes_for :users end And also the table-layout event_users user_id event_id user_type events id name users

Rails 3, nested multi-level forms and has_many through

≡放荡痞女 提交于 2019-11-27 10:11:50
问题 I'm trying to get it to work but it dosen't! I have class User < ActiveRecord::Base has_many :events, :through => :event_users has_many :event_users accepts_nested_attributes_for :event_users end class Event < ActiveRecord::Base has_many :event_users has_many :users, :through => :event_users accepts_nested_attributes_for :users end class EventUser < ActiveRecord::Base set_table_name :events_users belongs_to :event belongs_to :user accepts_nested_attributes_for :events accepts_nested