nested-attributes

WARNING: Can't mass-assign protected attributes

浪子不回头ぞ 提交于 2019-12-31 22:42:20
问题 I get this error "WARNING: Can't mass-assign protected attributes: races_attributes" , when following this http://railscasts.com/episodes/196-nested-model-form-part-1 on rails 3. Where Races are a component of Events. This is my models/race.rb: class Race < ActiveRecord::Base belongs_to :event attr_accessible :name, :unit end This is my models/event.rb: class Event < ActiveRecord::Base has_many :races, :dependent => :destroy accepts_nested_attributes_for :races attr_accessible :name, :date,

Rails after_initialize only on “new”

独自空忆成欢 提交于 2019-12-31 08:42:41
问题 I have the following 2 models class Sport < ActiveRecord::Base has_many :charts, order: "sortWeight ASC" has_one :product, :as => :productable accepts_nested_attributes_for :product, :allow_destroy => true end class Product < ActiveRecord::Base belongs_to :category belongs_to :productable, :polymorphic => true end A sport can't exist without the product, so in my sports_controller.rb I had: def new @sport = Sport.new @sport.product = Product.new ... end I tried to move the creation of the

Rails after_initialize only on “new”

萝らか妹 提交于 2019-12-31 08:42:16
问题 I have the following 2 models class Sport < ActiveRecord::Base has_many :charts, order: "sortWeight ASC" has_one :product, :as => :productable accepts_nested_attributes_for :product, :allow_destroy => true end class Product < ActiveRecord::Base belongs_to :category belongs_to :productable, :polymorphic => true end A sport can't exist without the product, so in my sports_controller.rb I had: def new @sport = Sport.new @sport.product = Product.new ... end I tried to move the creation of the

How do I Access Buttons inside a UserControl from xaml?

泪湿孤枕 提交于 2019-12-30 17:22:35
问题 At work I have several pages, each with buttons in the same places, and with the same properties. Each page also has minor differences. To that end, we created a userControl Template and put all the buttons in it, then applied that user control to all the pages. However, now it's rather hard to access the buttons and modify them from each page's xaml, because they are inside a UserControl on the page..... How do I elegantly access the buttons from each page? What I've tried: Currently, we

How do I Access Buttons inside a UserControl from xaml?

别等时光非礼了梦想. 提交于 2019-12-30 17:22:32
问题 At work I have several pages, each with buttons in the same places, and with the same properties. Each page also has minor differences. To that end, we created a userControl Template and put all the buttons in it, then applied that user control to all the pages. However, now it's rather hard to access the buttons and modify them from each page's xaml, because they are inside a UserControl on the page..... How do I elegantly access the buttons from each page? What I've tried: Currently, we

rspec + factory model testing nested attributes

最后都变了- 提交于 2019-12-30 11:53:08
问题 I have a rails4 app with rspec + factory_girl. I would like to test the validation that makes sure the product has at least one feature, competition, usecase and industry. The first 3 must belong to a product, but industry can exist on its own. I haven't tried to put industry in the test yet since I can't even make work the first 3. I tried the approach below in which I create a product factory that has product_feature, product_competition and product_usecase. For some reason it's not working

Rails 3 I18n label translation for nested_attributes in has_many relationship

…衆ロ難τιáo~ 提交于 2019-12-30 09:53:27
问题 Using: Rails 3.0.3, Ruby 1.9.2 Here's the relationship: class Person < ActiveRecord::Base has_many :contact_methods accepts_nested_attributes_for :contact_methods end class ContactMethod < ActiveRecord::Base attr_accessible :info belongs_to :person end Now when I try to customize the contact_method labels in I18n, it doesn't recognize it. en: helpers: label: person[contact_methods_attributes]: info: 'Custom label here' I have also tried: person[contact_method_attributes] This works just fine

Drop-Down-Menu for Many-to-Many relation in rails using nested attributes

隐身守侯 提交于 2019-12-30 05:24:08
问题 I have three tables via many-to-many-association: Supermarket, Product and Supply. Each Supermarket can hold many products and each product can be sold in many supermarkets. The association is build via the Supply-model. Supermarket: class Supermarket < ActiveRecord::Base attr_accessible :name, :address, :products_attributes has_many :supplies has_many :products, :through => :supplies accepts_nested_attributes_for :products end Product: class Product < ActiveRecord::Base attr_accessible :name

Rails: Getting rid of generic “X is invalid” validation errors

时光毁灭记忆、已成空白 提交于 2019-12-30 04:35:08
问题 I have a sign-up form that has nested associations/attributes whatever you want to call them. My Hierarchy is this: class User < ActiveRecord::Base acts_as_authentic belongs_to :user_role, :polymorphic => true end class Customer < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attributes_for :user, :allow_destroy => true validates_associated :user end class Employee < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy

Rails 4 - Nested form with accepts_nested_attributes_for controller setup?

荒凉一梦 提交于 2019-12-28 18:39:52
问题 I'm trying to make a nested form with form_for and fields_for . After much research and in-success, not working on my project anymore. I'm just trying to recreate a railscast to see what have I done wrong. I'm trying to re-create the example found at http://railscasts.com/episodes/196-nested-model-form-part-1 which shouldn't be that hard since the code is there, but I can't manage to create questions from the survey. Here is my code until now: rails new surveysays rails g scaffold survey name