nested-attributes

Swig error with Nested enums in C++

[亡魂溺海] 提交于 2019-12-07 02:02:46
I have a class similar to the following. It has a nested enum OptionTag. class MediaPacket { public: struct RtcpAppName { char mName[RTCP_APPNAME_LENGTH]; }; enum OptionTag { RESERVED = 0, PROFILE = 1, LATENCY = 2, PKTLOSS = 3, JITTER = 4, LEGACYMIX = 5, LASTTAG = 255 }; .... .... list<OptionTag> GetOptions(unsigned int ssrc) const; }; For this I created a swig interface as follows %module mediaopts_packet %include "stdint.i" //Redefining nested structure in swig struct RtcpAppName { char mName[RTCP_APPNAME_LENGTH]; }; %{ #define SWIG_FILE_WITH_INIT #include "../include/mediaopts_packet.h" %}

Rails Forms for Private Messaging

旧巷老猫 提交于 2019-12-06 22:54:39
I am trying to create a private messaging feature on my app between two users and I am running into trouble here First, here's Schema.rb create_table "conversations", :force => true do |t| t.string "conversation_subject end create_table "messages", :force => true do |t| t.string "content" t.integer "user_id" t.integer "conversation_id" end create_table "participants", :force => true do |t| t.integer "conversation_id" t.integer "user_id" end conversations has_many :messages, :participants users has_many :messages, :participants Form to start a conversation: <%= form_for @conversation do |f| %>

Rails nested forms with pre-defined fields as checkboxes

大城市里の小女人 提交于 2019-12-06 12:27:29
问题 I'm making a hotel app that includes Room and RoomAttribute models. The two models have a many_to_many relationship between each other through a join table. The attributes for each model are as follows: Room – room_number , room_type (e.g. "deluxe" or "suite"), and price . RoomAttributes – name (e.g. "Wireless Internet", "Cable TV", "Bath Tub"). The user will first create a set of room attributes, so that these can be selected as checkboxes every time a new room is created. For example, some

Nested attributes not working creating children with new parent

此生再无相见时 提交于 2019-12-06 11:23:25
问题 I have two models: class Shift < ActiveRecord::Base attr_accessible :ranges_attributes has_many :ranges accepts_nested_attributes_for :ranges, allow_destroy: true end class Range < ActiveRecord::Base belongs_to :shift validates :shift, presence: true end When, in my controller, I want to create a shift with ranges I'm getting: Shift.create! params[:shift] #ActiveRecord::RecordInvalid Exception: Validation failed: Shift ranges shift can't be blank If I remove validates :shift, presence: true

Correctly displaying nested models in my show view

元气小坏坏 提交于 2019-12-06 08:08:18
I'm new to rails and I'm slightly confused on how to properly display nested model attributes in a view. I'm using Rails 3.2.6. My 3 models here: class Company < ActiveRecord::Base attr_accessible :name, :vehicles_attributes, :engines_attributes has_many :vehicles, :dependent => :destroy accepts_nested_attributes_for :vehicles, :allow_destroy => true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } end class Vehicle < ActiveRecord::Base attr_accessible :company_id, :engines_attributes belongs_to :company has_many :engines, :dependent => :destroy accepts_nested_attributes_for

Rails nested form on many-to-many: how to prevent duplicates?

旧街凉风 提交于 2019-12-06 05:33:57
I've setup a nested form in my rails 3.2.3 app, it's working fine, my models are: class Recipe < ActiveRecord::Base attr_accessible :title, :description, :excerpt, :date, :ingredient_lines_attributes has_and_belongs_to_many :ingredient_lines accepts_nested_attributes_for :ingredient_lines end and: class IngredientLine < ActiveRecord::Base attr_accessible :ingredient_id, :measurement_unit_id, :quantity has_and_belongs_to_many :recipes belongs_to :measurement_unit belongs_to :ingredient end As above, a Recipe can have multiple IngredientLines and vice versa. What I'm trying to avoid is record

Rails validations are not being run on nested model

旧城冷巷雨未停 提交于 2019-12-05 23:27:37
I'm on Rails 3.2.8 and Ruby 1.9.3. I'm having trouble figuring out why the validations on the nested attributes are not being run or returning any errors. When I submit the form with nothing filled in, I get errors back for the parent model (User), but not for the child model (Account). In my code below, I have a User model which has_one owned_account (Account model), and an Account model that belongs_to an owner (User model). The Account model has a text field for a subdomain string. It seems that when I submit the form without including the subdomain field, the validations on the Account

Rails: How to make available parent attribute in setter method

邮差的信 提交于 2019-12-05 22:05:16
Context: I have a company model with many projects , having many tasks . The company also has many employees , which in turn have many tasks . Schema: Problem: I'm building a form to create a project where the user can add multiple tasks . Upon submission the form should create a single project record, one or more task records with hours and employee_id attributes and (!) check if the employee name already exists in the database or create a new one. I've approached this by adding jquery autocomplete to the form and defining a virtual attribute with a getter and setter method in my Task model.

Validate presence of nested attributes within a form

北城余情 提交于 2019-12-05 15:57:47
I have the following associations: #models/contact.rb class Contact < ActiveRecord::Base has_many :contacts_teams has_many :teams, through: :contacts accepts_nested_attributes_for :contacts_teams, allow_destroy: true end #models/contacts_team.rb class ContactsTeam < ActiveRecord::Base belongs_to :contact belongs_to :team end #models/team.rb class Team < ActiveRecord::Base has_many :contacts_team has_many :contacts, through: :contacts_teams end A contact should always have at least one associated team (which is specified in the rich join table of contacts_teams ). If the user tried to create a

accepts_nested_attributes_for causing SQLException

笑着哭i 提交于 2019-12-05 14:14:25
I would like to use accepts_nested_attributes_for to create an Article object that has_many Sections. class Article < ActiveRecord::Base has_many :sections, :order => "position", :dependent => :destroy belongs_to :categories accepts_nested_attributes_for :sections, :allow_destroy => true, :reject_if => lambda { |attributes| attributes['title'].blank? } validates_presence_of :name, :on => :create, :message => "An article must have a title" end class Section < ActiveRecord::Base belongs_to :article acts_as_list :scope => "article" has_attached_file :image, :styles => { :medium => "300x300>",