nested-forms

How does the HTML5 multiple file upload field map to a nested model in Rails 3?

被刻印的时光 ゝ 提交于 2019-12-03 16:14:38
问题 I'm trying to use the HTML5 multiple attribute on a file field in a nested form. The models are as follows: class Album < ActiveRecord::Base has_many :album_images has_many :images, :through => :album_images accepts_nested_attributes_for :images end class Image < ActiveRecord::Base has_many :album_images has_many :albums, :through => :album_images mount_uploader :filename, ImageUploader validates_presence_of :filename end The view: <%= semantic_form_for @album, :url => upload_path do |f| %> <

Deeply nested Rails forms using belong_to not working?

我与影子孤独终老i 提交于 2019-12-03 15:50:39
I'm working on a messy form which among other things has to manage a section with two-level nesting. It's almost working, but there's a snag and the only thing I can see that's different from other deeply-nested forms that work is that there's a belongs_to relationship rather than has_many. Here are the models: Event has_many :company_events, :dependent => :destroy accepts_nested_attributes_for :company_events CompanyEvent belongs_to :company accepts_nested_attributes_for :company, :update_only => true belongs_to :event belongs_to :event_type Company has_many :company_events has_many :events,

Form with nested attributes with a has_one association not working in Rails 3

放肆的年华 提交于 2019-12-03 12:38:41
问题 I'm tring to set values for two models that have a has_one association using accepts_nested_attributes_for, but nothing in the fields_for is being shown on the view. I have confirmed the same code works on Rails 2.x, and it works fine when its a has_many. Code below. Model class Parent < ActiveRecord::Base has_one :child accepts_nested_attributes_for :child end class Child < ActiveRecord::Base belongs_to :parent end Controller def new @parent = Parent.new @parent.build_child end View <%= form

nested_form/cocoon: is it okay to use table rows for nested fields?

℡╲_俬逩灬. 提交于 2019-12-03 09:27:26
问题 I normally don't use tables for forms, but when having a nested form (when using nested_form or cocoon gem), is it okay then to put each set of form elements inside a table row? To me, this seems pretty intuitive: every row in the table represents an object. But neither the nested_form nor the cocoon gem add tables in their examples by default, so I wonder whether using forms isn't the best way to go? 回答1: Yes. If you are inputting tabular data then you should use a table. I haven't tested

Nested Simple Form in Rails4 - has many through, save multiple records

巧了我就是萌 提交于 2019-12-03 08:48:05
I've got a standard has_many through relationship. Humans have many Orcs through a join table Interactions. The interactions is just a table and model; no controller or views. Using the simpleform gem in Rails 4, I want to make a form from the humans page, in order to select multiple orcs out of the pool of all orcs. Once submitted, I want it to create/update as many records in the interactions table, each with the human id, and as many orc ids were selected. : AKA list notation Make a form from one end (humans) List out all the orcs in the form Select multiple orcs from that list Save as many

Rails Nested Forms Attributes not saving if Fields Added with jQuery

瘦欲@ 提交于 2019-12-03 08:43:18
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 can not figure out what is not being passed in the javascript that is failing to communicate that the form object needs to be saved. Any help would be great. class Itinerary < ActiveRecord::Base accepts_nested_attributes_for :trips end itinerary/new.html <% form

Rails - How to manage nested attributes without using accepts_nested_attributes_for?

浪尽此生 提交于 2019-12-03 08:33:30
My problem is I've run into limitations of accepts_nested_attributes_for, so I need to figure out how to replicate that functionality on my own in order to have more flexibility. (See below for exactly what's hanging me up.) So my question is: What should my form, controller and models look like if I want to mimmic and augment accepts_nested_attributes_for? The real trick is I need to be able to update both existing AND new models with existing associations/attributes. I'm building an app that uses nested forms. I initially used this RailsCast as a blueprint (leveraging accepts_nested

Alternative for accepts_nested_attributes_for - maybe virtus

心不动则不痛 提交于 2019-12-03 04:55:51
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 example still using accepts_nested_attributes_for (find the full example here ): Models class Person <

Form with nested attributes with a has_one association not working in Rails 3

落爺英雄遲暮 提交于 2019-12-03 02:57:48
I'm tring to set values for two models that have a has_one association using accepts_nested_attributes_for, but nothing in the fields_for is being shown on the view. I have confirmed the same code works on Rails 2.x, and it works fine when its a has_many. Code below. Model class Parent < ActiveRecord::Base has_one :child accepts_nested_attributes_for :child end class Child < ActiveRecord::Base belongs_to :parent end Controller def new @parent = Parent.new @parent.build_child end View <%= form_for @parent do |f| %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div>

Adding dynamic fields to nested form through AJAX

时光怂恿深爱的人放手 提交于 2019-12-03 02:54:25
I've been watching and reproducing these railscasts on my app: 196-nested-model-form-part-1 and 197-nested-model-form-part-2 . I do not yet have a pro account so i can't watch the revised episode. I'm developing under rails4 (edge) and link_to_function has been deprecated in favor of unobstrusive JS (which is great). I'll keep the example of the above railscasts (i.e. survey/question). What i'd like to do is to use the question's partial through unobstrusive javascript and i just don't know how and where i should do this. I was thinking of two ways to do so : First way would be to add in my