nested-forms

Nested Attributes for Polymorphic Models

Hi, In my code, I have 4 models: Plan, Choice, Venue, CustomSuggestion, in order to allow users to create "plans" which consist of choices, which in turn consists of a suggested. My code looks something like this: class Plan < ActiveRecord : Base has_many :choices end class Choice < ActiveRecord : Base belongs_to :plan belongs_t...

Multi-Model Forms with Image Upload

Hi, I'm trying to create a poll object which has many answers. Each answer can have an image attached. How can I create a form that allows me to enter the question and add a variable number of answers (each with their attached image). I'd also preferably want to allow preview of the images uploaded. My idea so far is to have a sub-form...

nested models, validations, and deletions

After struggling with this for hours, I think I've finally developed a solution to the following problem. I have the code here: http://pastie.org/767503 . What I am doing is allowing for classic http modification of a logic expression like (OR (AND ItemsFromCollectionPredicate) (AND TruePredicate)) which is the params hash below "co...

is there better way to count for three level nested forms

I have a nested forms like: class House < ActiveRecord::Base has_many :rooms accepts_nested_attributes_for :rooms attr_accessible :rooms_attributes end class Room < ActiveRecord::Base has_one :tv accepts_nested_attributes_for :tv attr_accessible :tv_attributes end class Tv belongs_to :user attr_accessible :manufactur...

Rails nested forms

I would like to create form with text_fields TITLE CONTENT TAGS I have Post (TITLE, CONTENT) and Tag (TAGS) model. TAGS is a single text field. What do I have to do to save TAGS to Tag model. Let say I write 'banana, juice, new tag' in the TAGS field, how can this be parsed into array and then save in the Tag model. Thx! ...

rails nested object form and namespaced controller

i have a nested object like this: class Work < ActiveRecord::Base belongs_to :issue belongs_to :author has_many :pages, :class_name => 'Work' accepts_nested_attributes_for :pages, :allow_destroy => true end class Page < ActiveRecord::Base belongs_to :work end and i have a form to create/edit a work, with fields for the nest...

Need help modifying multiple models example from advanced rails recipes book

I'm developing a simple rails app for my own use for learning purposes and I'm trying to handle 2 models in 1 form. I've followed the example in chapter 13 of Advanced Rails Recipes and have got it working with a few simple modifications for my own purposes. The 2 models I have are Invoice and InvoicePhoneNumber. Each Invoice can have s...

Rails checkout form with multiple models

I'm creating a shopping cart based on the one in Agile Web Development With Rails (version 3). I have it set up where "items" are added to a "cart", then upon starting the checkout process, they are added to an "order" object as "line_items". "line_items" represent one "item" in any quantity. Up to this point, I'm not deviating from the ...

Nested Rails forms and using label_tag, checkbox_tag and other form_tag functions

In regular forms in Ruby on Rails, if using form_for to build a model, as the API docs state, form_for doesn't create an exclusive scope, and it's possible to use form_tag functions within the form_for form. For example: <% form_for :person, @person, :url => { :action => "update" } do |f| %> First name: <%= f.text_field :first_name %...

Rails nested form with has_many :through, how to edit attributes of join model?

How do you edit the attributes of a join model when using accepts_nested_attributes_for? I have 3 models: Topics and Articles joined by Linkers class Topic < ActiveRecord::Base has_many :linkers has_many :articles, :through => :linkers, :foreign_key => :article_id accepts_nested_attributes_for :articles end class Article < Active...

Rails - Should an object's types be in its own model?

I have a contact, and contact has_many :phones. The phones table has a column named, phones_desc, where I want to include the type of phone number the user has saved. My question / Best practice Should I provide a select with manually provided options (such as "mobile", "work", "home")... -or- ...create a new model named phones_type...

Rails nested form using file_field element

I am using code found at Railscast 197 to create nested forms using jQuery. The challenge I am facing is that the nested model uses a file_field element, and because of this when looking at the edit view I just see a list of empty file_field elements. Is there a way I can tell rails to display something else (like a disabled text_field) ...

Nested forms in rails = has_many :confusions :(

I have a user and a profile model. One user can have many profiles. I need to access only one information from the profiles section (viz the phone number) in my user model during the user creation process. Hence I'm trying to get it done through attr_accessible. My user.rb looks like this. has_many :profiles attr_accessible :handle, :em...

nested form that is placed on many pages throughout application

Hi I have a form with nested attributes that I need to place on many different pages. Not necessarily the model it belongs to. So I have this form on the battalions show page. The user information is created just fine, but the user has_many roles and these attributes are not being created. I have many other nested forms that work just f...

Using polymorphic models in nested forms

For an answer model I want to save different types of answer (e.g.decimal, string, text, ...) in different tables. Polymorphic seems the way to go, but how can I receive the users answers from a nested form using fields_for? I now in advance, what type is asked for, but how do I tell in the controller in which table the answer should be...

Form is creating already loaded attributes in addition to new attributes, how do I ignore the first?

In my application you: Have an admin user that signs on and that user has a role (separate model), then I use the declarative_authorization plugin to give access to certain areas. That admin user can also register new users in the system, when they do this (using Authlogic) they fill out a nested form that includes that new users' ro...

rails build method for complex model with days of the week

I have a set of nested models for storing prices for individual rooms. Ie. Places Rooms Room_rates Each model has the necessary accepts_nested_attributes_for and has_many belongs_to association and I have a form and a build method which works perfectly for the initial creation. My question is how to make a smarter contro...

rails complex form and ordering with build

I have complex form similar to a recent Ryan Bates screencast The nested elements work fine however. I'm creating or updating a grid of data such as this through a form where the day's prices are the input. My problem begins when they leave one blank. I have the nested_attributes_for option for not saving nils and it works, if they o...

rails validation contigent on multiple elements

I've been using accepts_nested_attributes_for for a few different models and I've got an odd situation. I can skip creation blanks thru the top model, and I can validate_presence of individual records thru the bottom, but is it possible to do a most complex validation on a set of records? I have the models Rooms and Rates. Rooms has_m...

How to omit existing child records in a nested form in rails?

In my application an User has many Projects. I want to create a "add many projects" form, so the User can create many Projects at once. It seemed to me that the quickest way was to make a User form with Project fields nested in it, and omit the User fields. This way when the form is submitted, the User is saved and all the new Project r...