nested-forms

expected Hash (got Array) for param 'samples'

匆匆过客 提交于 2019-12-10 12:43:30
问题 I have been following Railscasts episodes of Nested forms and complex forms. During the time of creating multiple model in a single form I was able to edit, update, delete and create records for sample models that were nested in the Batch model. I have been breaking my head from a long time and tried searching around as well but could not get any right solution for solving this problem. my development log file gives me the following error. ERROR MESSAGE: Status: 500 Internal Server Error

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 form & habtm

流过昼夜 提交于 2019-12-10 09:25:06
问题 I am trying to save to a join table in a habtm relationship, but I am having problems. From my view, I pass in a group id with: <%= link_to "Create New User", new_user_url(:group => 1) %> # User model (user.rb) class User < ActiveRecord::Base has_and_belongs_to_many :user_groups accepts_nested_attributes_for :user_groups end # UserGroups model (user_groups.rb) class UserGroup < ActiveRecord::Base has_and_belongs_to_many :users end # users_controller.rb def new @user = User.new(:user_group_ids

Rails 3: Why an empty nested form generates a hidden input field?

喜夏-厌秋 提交于 2019-12-09 23:47:26
问题 Why this: # edit.html.erb <%= form_for @product do |f| %> <%= f.fields_for :shop do |sf| %> # Nothing here <% end %> <% end %> generates a hidden input field: <input type="hidden" value="23" name="product[shop_attributes][id]" id="product_shop_attributes_id"> ? Relevant controller code: def edit @product = Product.find(params[:id]) end 回答1: It'll be because the @product you're editing has a shop. Rails has inserted that in the fields_for so that when the form is submitted, it knows which shop

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,

Problems with nested form fields showing up

爱⌒轻易说出口 提交于 2019-12-09 14:17:59
问题 I'm attempting to implement nested object forms for my site, using Ryan Daigle's blog post as a guide (http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes). For some reason, the nested form fields don't appear in the view. class Instruction < ActiveRecord::Base has_many :steps accepts_nested_attributes_for :steps end class Step < ActiveRecord::Base belongs_to :instruction end <% form_for @instruction do |instruction_form| %> <%= instruction_form.error_messages %

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

remove_fields & add field link not working on nested form in rails 3.0.9

本秂侑毒 提交于 2019-12-09 03:39:04
问题 I am following Ryan bates neted_forms episode 1 & 2 from rails casts, I have already implemented the nested-forms functionality in one of my project before & it's working fine without any error, But in my new project I am using the same reference from rails casts but remove & add field is not working. Here is my model has_many :contacts, :dependent => :destroy accepts_nested_attributes_for :contacts, :reject_if => lambda { |a| a[:contact_name].blank? }, :allow_destroy => true The form on

Rails 3 Nested Models unknown attribute Error

蓝咒 提交于 2019-12-09 00:06:39
问题 I have a model "Issue" and a nested Model "Relationship" In the issue.rb I have mentioned: has_many :relationships, :dependent => :destroy accepts_nested_attributes_for :relationships, :allow_destroy => true In relationship.rb I have mentioned: belongs_to :issue Following Ryan Bates Railcast#196 I have the following in my issues_controller: relationship = @issue.relationships.build However, I am encountering an error "unknown attribute: relationship" Am I doing something incorrectly here? I

Associated models and a nested form with validation not working

。_饼干妹妹 提交于 2019-12-08 18:17:30
Update2: I've cleaned up the code, which seems to have solved some of the problems. I've posted the new code as a new question here . Update: Organization and User have a 1:many relationship. My question concerns a joined signup form where both an organization and user are required. After maxcal's help on the original post, I've written a new create method for my nested form ("organization has many users"), as shown below. Also I added begin...rescue...end to the create method. The situation/problem now: Submitted with all valid info it works correctly. Submitted with invalid info for