nested-forms

Rails: validate presence of parent_id in has_many association

I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model. However, when creating a new project with tasks, the project_id won't be available until the record saves, therefore I can't use validates_presence_of :project_id. So my que...

How Do I Prevent Rails From Treating Edit Fields_For Differently From New Fields_For

I am using rails3 beta3 and couchdb via couchrest. I am not using active record. I want to add multiple "Sections" to a "Guide" and add and remove sections dynamically via a little javascript. I have looked at all the screencasts by Ryan Bates and they have helped immensely. The only difference is that I want to save all the section...

AssociationTypeMismatch with Expected Type on Nested Model Forms

I'm getting this exception when doing a nested model form: ActiveRecord::AssociationTypeMismatch in RecipesController#update Ingredient(#35624480) expected, got Ingredient(#34767560) The models involved are Recipe and Ingredient. Recipe has_many and accepts_nested_attributes_for :ingredients, which belongs_to :recipe. I get this e...

polymorphic nested comments

Hi all i'm getting this error when I try to post a comment on a post. The error Cannot redirect to nil! /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:1104:in `redirect_to' /Users/Mister/dev/blog/app/controllers/comments_controller.rb:9 Comments/Controller: class CommentsController < ApplicationCon...

Nested form problem in Rails : NoMethodError in Show

I'm trying to build a simple product backlog application to teach myself Rails. For each product, there can be multiple product backlog entries, so I want to create a product view that shows the product information, all the backlog entries for the product, and includes a nested form for adding more backlog entries. Everything works unti...

rails nested attributes

I am using rails 3.0.0.beta3 and I am trying to implement form with nested attributes using :accepts_nested_attributes_for. My form is nested to three levels: Survey >> Question >> Answer. Survey has_many Questions, and Question has many Answers. Inside the Survey model, there is :accepts_nested_attributes_for :questions and inside...

nested form & habtm

so 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 ...

Simply trying to submit a simple form inside form, weird behavior

I have a ad banner that has a form and this is used by 3rd party site owners that grab this code and have this banner on there site. Since some sites that use this banner have a <form> wrapping there entire site i have found that the banners form doesn't submit it rather submits the outer form. Here is the code: <form onSubmit="retu...

Problem with Railscast #197 - Nested Model Form Part 2

I'm trying to implement Ryan's Railscast #197 in a system with Questions, Answers, and (multiple choice) Options. http://railscasts.com/episodes/197-nested-model-form-part-2. I have successfully implemented the nesting among these forms/partials. The simpler 'check box' way to delete records works properly. The problem occurs when I tr...

Rails nested form with nested resource: update belongs_to association when creating new has_many

Hey guys, I've been beating my head against a wall with a particular use case for nested forms (I'm using Rails 2.3.5). Essentially I have Project and Payment models that looks like this class Project < ActiveRecord::Base has_many :payments end class Payment < ActiveRecord::Base belongs_to :project accepts_nested_attributes_for ...

How to manually build a correct nested form with accepts_nested_attributes_for?

I'm trying to manually build form fields for a testing purpose. I got the following models: class Bedroom < ActiveRecord::Base has_many :booked_bedrooms has_many :bookings, :through => :booked_bedrooms end class Booking < ActiveRecord::Base has_many :booked_bedrooms has_many :bedrooms, :through => :booked_bedrooms a...

How do I fix the fields_for error: @ "is not allowed as an instance variable n" in Rails?

My goal is to enable a user to be able to submit multiple NewsImages from a parent Blog form. My Blog model looks like this: # == Schema Information # Schema version: 20091006171847 # # Table name: blogs # # id :integer(4) not null, primary key # title :string(255) # body :text # profile_id :inte...

PHP: populating a nested array from flat scalar values

PROBLEM I have a nested PHP array that I need to populate from flat scalar values. The problem is I cannot know ahead of time what the structure of the nested PHP array will be until I get the request to fill in the flat scalar values. EXAMPLE // example where we populate the array using standard PHP $person['contact_info']['fname']...

Ruby on rails: fields_for do nothing if defined submodel_attributes=

I have such code in new.erb.html: <% form_for(@ratification) do |f| %> <%= f.error_messages %> <% f.fields_for :user do |fhr| %> <p> <%= fhr.label :url %><br /> <%= fhr.text_field_with_auto_complete :url %> </p> <% end %> <% end %> If i have empty Ratification.rb it is ok, fields_for works ok. But if I wr...

Rails 3 CRUD shallow nested model

Hello ! I'm trying to use this example but it doesn't work. I guess it's because I use a shallow nested model ! I get this error : Template is missing Missing template pprojects/create with {:formats=>[:html], :handlers=>[:builder, :erb, :haml, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} It looks like my app is trying to do HTML and no ...

Unknown Attributes on nested form in Rails

Hi all, I'm having trouble getting my InventoryItem to accept nested attributes which is strange. In my script/console, I did the following: >> InventoryItem.create!(:name => 'what', :image_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }]) ActiveRecord::UnknownAttributeError: unknown attribute: image_a...

Updating nested params not working.. whats wrong?

Im trying to update some nested params from a form. I can see that the parameters im getting from the form is correct, however the database dont get updated. the view <% form_for @order do |f| %> <% f.fields_for :itemgroups do |ff, i| %> <% ff.fields_for :items do |fff| %> <%= ff.text_field :text, :id => "textField", :disab...

jQuery - How to select an element that is created after page load

I have a page that uses Ryan Bates nested_form plugin. The plugin is used when you have form based on one model and then additional fields that belong to another model. For example if I had a form that created categories, and at the same time I wanted to add items to the new category, my form would contain input fields for the category m...

combining jquery accordion and rails nested forms

Hi, I'd like to generate a form with nested object forms like this (in haml): - form_for @parent do |parent_form| - parent_form.fields_for :children do |child_form| = child_form.label :first_name = child_form.text_field :first_name ... and I'd like to place the child forms in a jquery ui (1.8.2) accordion, like this (I think...

Automatically build a nested model form with using the 'link_to_add_fields helper'

Ive created a nested model form the RailsCasts Nested Model Form Part 2 example and have it working with Rails 3 and JQuery. Currently, a user can create a new project and click a link to add new tasks, and within each new task, click a link that will allow them to add new assignments to each task. Here's the link to create a new task ...