nested-forms

Getting "unknown attribute: user" while using nested models

Hi, I'm getting an error when I submit the form http://pastie.org/846712 I tried changing "f.fields_for :users do |builder|" to "f.fields_for :user do |builder|", but it generated nothing. To give you a picture of how my accounts controller looks like: http://pastie.org/846714 And the error I'm getting is on: http://pastie.org/846715 T...

Marking multi-level nested forms as "dirty" in Rails

I have a three-level multi-nested form in Rails. The setup is like this: Projects have many Milestones, and Milestones have many Notes. The goal is to have everything editable within the page with JavaScript, where we can add multiple new Milestones to a Project within the page, and add new Notes to new and existing Milestones. Everythi...

Nested form child only updates if parent changes.

In this video (10 sec) you can see that the nested attribute is only updated if it's parent model is changed. Using rails 3.0.0.beta and full project is on github. Summary of models and form: class Project < ActiveRecord::Base has_many :tasks accepts_nested_attributes_for :tasks end class Task < ActiveRecord::Base belongs_to :p...

Adding 'tags' to a Rails' application with 'nested model forms'

Im learning Rails and have built a'store' application from the 'Agile Development w/ Rails' book. Ive gone beyond the lesson in the book and Im trying to add 'tags' to each product in the the store. Id then like a user to be able to click on a tag (that will be in a list in the sidebar), and have the store repopulate with those tagged ...

How to access nested params

I would like to get some nested params. I have an Order that has many Items and these Items each have a Type. i would like to get the type_id parameter from the controllers create method. @order = Order.new(params[:order]) @order.items.each do |f| f.item_type_id = Item_type.find_by_name(f.item_type_id).id end The reason is that i wa...

Rails Nested Forms Attributes not saving if Fields Added with jQuery

Hi I have a rails form with a nested form. I used Ryan Bates nested form with jquery tutorial and I have it working fine as far as adding the new fields dynamically. But when I go to submit the form it does not save any of the associated attributes. However if the partial builds when the form loads it creates the attribute just fine. I...

I am trying to manipulate nested parameter before saving the model, but i miss something

I cant see what im missing. I have and Order with nested Items, these Items each have a Kind. I want to manipulate the kind_id param from each Item but the "f[:kind_id]" always return 0. @order.items.each do |f| f[:kind_id] = Kind.find_by_name(f[:kind_id]).id end the params i get is {"authenticity_token"=>"7wz7ARjwcVvCR/bpp/T04JQI...

Nested form using accepts_nested_attributes_for with pre-population from another table

I'm using Rails 2.3.5 and have a nested structure as follows: Lists has_many Items Items_Features has_many Features Items_Features has_many Items Items_Features has a text field to hold the value of the feature Then I have a nested form with partials to update and display this so that it updates Lists, Items and Items_Features What...

Accepts Nested Attributes For - edit form displays incorrect number of items ( + !map:ActiveSupport::OrderedHash {} )

Hi, I have a teacher profile model which has many subjects (separate model). I want to add subjects to the profile on the same form for creating/editing a profile. I'm using accepts_nested_attributes for and this works fine for creation. However on the edit page I am getting a very strange error - instead of seeing 3 subjects (I added t...

double accepts_nested_attributes_for

does anyone know if it is possible to do a double nested form for. so that i could upload images to a set from an article form. e.g. Article has_many :image_sets ImageSet belongs_to :article has_many :images Image belongs_to :image_set ...

Why do I get a AssociationTypeMismatch when creating my model object?

Hi I get the following error: ActiveRecord::AssociationTypeMismatch in ContractsController#create ExchangeRate(#2183081860) expected, got HashWithIndifferentAccess(#2159586480) Params: {"commit"=>"Create", "authenticity_token"=>"g2/Vm2pTcDGk6uRas+aTgpiQiGDY8lsc3UoL8iE+7+E=", "contract"=>{"side"=>"BUY", "currency_id"=>"488525179", ...

How to add and remove nested model fields dynamically using Haml and Formtastic

We've all seen the brilliant complex forms railscast where Ryan Bates explains how to dynamically add or remove nested objects within the parent object form using Javascript. Has anyone got any ideas about how these methods need to be modified so as to work with Haml Formtastic? To add some context here's a simplified version of the p...

Nested form data binding with Lists of Objects in Spring MVC

Hi, I have an object like so: public class FormFields extends BaseObject implements Serializable { private FieldType fieldType; //checkbox, text, radio private List<FieldValue> value; //FieldValue contains simple string/int information, id, value, label //other properties and getter/setters } I loop through a list of FormFields a...

Problem accessing variable in a nested form partial

I have a nested form in a rails view that is called like this <% f.fields_for :invoice_item_numbers do |item_no_form| %> <%= render 'invoice_item_number', :f => item_no_form %> <% end %> and the partial (_invoice_item_number.html.erb) looks like this <div class='invoice_item_numbers'> <% if f.object.new_record? %> <li><%=...

problems with build params for accepts_nested_attributes_for

I'm trying to add the user_id to a nested attribute that gets built by a parent controller but it doesn't seem to have the desired effect? Ie. I have a model called Place.rb which accepts_nested_attributes_for :reviews and has_many :reviews, :as => :reviewable, :dependent => :destroy The nested attribute works fine and I build it insid...

undefined method `build_users' with nested models

I've got into trouble with nested attributes. Here is my Account model : class Account < ActiveRecord::Base has_many :products has_many :blogs has_many :openings has_many :users has_one :logo, :class_name => "AccountPicture" has_one :address, :class_name => "AccountAddress" has_and_belongs_to_many :options...

validates_uniqueness_of in nested model rails

I have a Project model which accepts nested attributes for Task. class Project < ActiveRecord::Base has_many :tasks accepts_nested_attributes_for :tasks, :allow_destroy => :true end class Task < ActiveRecord::Base validates_uniqueness_of :name end Uniqueness validation in Task model gives problem while updating...

How to create a view to manage associations between HABTM models? (Rails)

Hello, I am using Ruby on Rails and need to create a view that allows the creation of records through a HABTM relationship to another model. Specifically, I have the following models: Customer and ServiceOverride, and a join table customers_serviceoverrides. Using the customer view for create/update, I need to be able to create, update a...

Rails: what are the benefits of using nested routes / forms

I am starting to use some nested routes which is definitely a different way of planning things and I'm really failing to see added benefits. So what are they? ...

how to save nested form attributes to database

I am not really understand how's the nested attributes work in Rails. I have 2 models, Accounts and Users. Accounts has_many Users. When a new user filled in the form, Rails reported User(#2164802740) expected, got Array(#2148376200) Is that Rails cannot read the nested attributes from the form? How can I fix it? How can I save the d...