nested-attributes

I can't create model objects using accepts_nested_attributes_for. It won't create the nested object

故事扮演 提交于 2019-12-10 20:37:25
问题 My model structure looks like this: Board has_many Topics. Topic has_many Posts. app/models/board.rb class Board < ActiveRecord::Base has_many :topics end app/models/topic.rb class Topic < ActiveRecord::Base belongs_to :user belongs_to :board has_many :posts accepts_nested_attributes_for :posts validates :title, presence: true, length: { maximum: 255 } validates :user_id, presence: true validates :board_id, presence: true ... end app/models/post.rb class Post < ActiveRecord::Base belongs_to

Best_In_Place inline edits with nested attributes

拜拜、爱过 提交于 2019-12-10 15:06:29
问题 I am currently trying to use the best_in_place gem in order to do inline editing within an HTML table. I am showing a cart in cart's show view. Within the cart's show view, I have the ability to add lineItems. When an LineItem is created, a new Available record is also created with a lineItem_id and then it's shown in the cart with its lineitem. Both the Cart and LineItem tables come from an external database and because of that, I can't add columns to so that is why I can't just add an

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

巧了我就是萌 提交于 2019-12-10 12:22:23
问题 I have a House model, which has_many house_rules class House < ActiveRecord::Base has_many :house_rules, dependent: :destroy accepts_nested_attributes_for :house_rules, reject_if: :all_blank, allow_destroy: true end Here is the house_rule model class HouseRule < ActiveRecord::Base belongs_to :house enum rule_type: { predefined: 0, user_defined: 1 } enum allowed: { no: 0, yes: 1 } end Here are the other columns of house_rules table create_table "house_rules", force: :cascade do |t| t.integer

Correctly displaying nested models in my show view

送分小仙女□ 提交于 2019-12-10 11:22:59
问题 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

nested attributes in simple_form returns mass assignment error

主宰稳场 提交于 2019-12-09 22:36:47
问题 Models: class Topic < ActiveRecord::Base has_many :posts, :dependent => :destroy validates :name, :presence => true, :length => { :maximum => 32 } attr_accessible :name, :post_id end class Post < ActiveRecord::Base belongs_to :topic, :touch => true has_many :comments, :dependent => :destroy accepts_nested_attributes_for :topic attr_accessible :name, :title, :content, :topic, :topic_attributes end View: <%= simple_form_for :post, :url => { :controller => :posts, :action => "create" } do |f| %>

How to do the Hibernate validation on the nested list objects?

最后都变了- 提交于 2019-12-09 16:53:29
问题 I need to validate the objects which are stored in the list on my form bean object. Below is my form bean object. public class Role implements java.io.Serializable { // Fields private int roleId; @NotBlank private String roleName; private boolean active; @Valid private List<Module> modules; // getters anfd setters } and below is my object which is present in the list of my main form bean object public class Module implements Serializable { private int id; @NotBlank private String moduleName;

has_many nested form with a has_one nested form within it

别来无恙 提交于 2019-12-09 15:52:08
问题 I am currently trying to make a form for a model, which has a dynamic number of nested models. I'm using Nested Forms (as described in RailsCasts 197). To make things even more complicated, each of my nested models has a has_one association with a third model, which I would also like to be added to the form. For any who are wondering about over normalization or an improper approach, this example is a simplified version of the problem I'm facing. In reality, things are slightly more complex,

Alternative for accepts_nested_attributes_for - maybe virtus

六月ゝ 毕业季﹏ 提交于 2019-12-09 05:08:55
问题 I'm relatively new to rails and finally found the right way to use accepts_nested_attributes_for . However, there are some serious resources on the web who say that using accepts_nested_attributes_for is generally a bad practice (like this one). What changes are necessary to avoid accepts_nested_attributes_for and in which folder would you put the additional class-file (I guess one needs an additional class). I read that virtus is appropriate for that. Is that right? Here is a very basic

Can nested attributes be used in combination with inheritance?

亡梦爱人 提交于 2019-12-09 03:13:36
问题 I have the following classes: Project Person Person > Developer Person > Manager In the Project model I have added the following statements: has_and_belongs_to_many :people accepts_nested_attributes_for :people And of course the appropriate statements in the class Person . How can I add a Developer to a Project through the nested_attributes method? The following does not work: @p.people_attributes = [{:name => "Epic Beard Man", :type => "Developer"}] @p.people => [#<Person id: nil, name:

rails simple_nested_form_for fields_for wrong number of arguments

时间秒杀一切 提交于 2019-12-08 16:37:43
问题 So I'm building a form in rails 3.1, using <%= simple_nested_form_for(@person, :url => collection_url, :html=>{:multipart => true}) do |f| %> <%= render :partial => "form", :locals => { :f => f } %> <% end %> but this line in the partial is causing the problem: <h2>Badges</h2> <ul id="certifications"> // this following line is raising the error "wrong number of arguments (4 for 3)" <%= f.fields_for :certifications do |certification_form| %> <%= render :partial => 'certification', :locals => {