nested-forms

Rails - Nested form data not appearing in “edit” page despite showing in “show” page

我是研究僧i 提交于 2019-12-11 05:43:14
问题 I have a rails app in which I have a Project model, a Team model and a User model. I am trying to create a nested form within the Project form using the Team model, and in this nested form I have a collection_select field which allows the user to select an existing User's email (from the User model) and input the data retrieved in a column called :member within the Team model. The issue at hand is that that after saving the form, the fields from the nested form appear in the show page,

Complex Form Nesting in Rails - How to create the desired hash / array params output

别来无恙 提交于 2019-12-11 03:03:21
问题 I'm trying to figure out how to properly handle the params hash so as I dont pass params that should be nested multiple times.. Here is a simplified(removed not-needed info like labels etc) of my html.slim code (using simple_form): = f.simple_fields_for :room do |r| - (1..4).each do |room| = r.input 'adults',:collection => 1..4,:input_html => {:name => "room[adults][]"} = r.input 'children',:collection => 0..2,:input_html => {:name => "room[children][]"} - (1..2).each do |child| = r.input

multiple image uploads in a nested form with carrierwave

微笑、不失礼 提交于 2019-12-11 01:51:18
问题 I'm following railscasts episode 381 in an attempt to allow multiple image uploads to my app with the carrierwave gem & jQuery File upload. My app is for a college project & is set up with a hikingtrails model which has many & accepts nested attributes for a pics model . After I set the multiple option of the file_field to true & hard-coding the input name attribute i.e. <%= form.file_field :image, multiple: true, name: "pic[image]" %> , carrierwave stops working, it doesn't upload a single

rails link_to_add_fields not adding fields with has_many :through (with nested form inside)

天涯浪子 提交于 2019-12-10 22:20:17
问题 I have the link_to_add_fields code working for many other models, but here it is not working. I use Ryan Bates screen casts to model how I do mine. What might different with this is that I have 2 nested models in one partial. Half the table fields are from model a (journals), and the other are from model b (journal_entries) and all are based off a Leases model. The table looks like the following, [xx] are input fields. It looks kinda like a data grid. Dated |Memo |Account |Credit | ----------

rails nested form assign unique id to generated field

佐手、 提交于 2019-12-10 20:01:06
问题 I want to assign unique Id to each row generated by nested form . I looked this question Creating unique id for <fieldset> when using form_for Rails Nested Model Form but this doesn't solve my problem . 回答1: Actually, the solution given by Anil Maurya only works for items that have been dynamically added via javascript using link_to_add provided by the gem. But for me, it would leave new_association for already existing items. In order to properly identify every nested element (even the

Rails 4 nested form - no implicit conversion of Symbol into Integer

笑着哭i 提交于 2019-12-10 18:51:24
问题 In my rails 4 app, I have a triple nested route: devise_for :users do resources :foo do resources :marflar end end And I have a form for creating a new Foo with an embedded Marflar object: <%= form_for(@foo) do |f| %> <%= f.text_field :foo_attr %> <%= f.fields_for :marflars_attributes do |marflars_form| %> <%= marflars_form.text_field :marflar_attr %> <% end %> <%= f.submit %> <% end %> But when I submit the form I get: TypeError in FoosController#create no implicit conversion of Symbol into

Nested forms in rails 3.1

孤街浪徒 提交于 2019-12-10 18:46:17
问题 I have a problem with nested forms: rails 3.1 doesn`t render fields_for blocks when it should (when editing existing record for example). Since I`m not confident enough in my english, I`ve made a small example app: New Action: def new @manga = Manga.new 3.times {@manga.volumes.build} end Form Code: <%= form_for @manga do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <% f.fields_for :volumes do |builder| %> <p> <%= builder.label :cover_link, "Link

nested has_one in active admin

风流意气都作罢 提交于 2019-12-10 17:46:28
问题 I'm using Rails 3.0.10 and ActiveAdmin 0.3.2. I have a problem with nested form and an has_one association. Using an has_many I can get nested forms but I really need to understand and use an has_one in this case. Model: class Article < ActiveRecord::Base belongs_to :section has_one :seo accepts_nested_attributes_for :seo end class Seo < ActiveRecord::Base belongs_to :article end How write app/admin/article.rb ? Thanks for any suggestions! 回答1: I'm having exactly the same problem, and here's

accepts_nested_attributes_for validation

♀尐吖头ヾ 提交于 2019-12-10 16:02:49
问题 I'm using Rails 2.3.8 and accepts_nested_attributes_for. I have a simple category object which uses awesome_nested_set to allow nested categories. For each category I would like a unique field called code. This would be unique for the category per level. Meaning parent categories will all have unique codes and sub categories will be unique within their own parent category. EG: code name 1 cat1 1 sub cat 1 2 cat2 1 sub cat 1 2 sub cat 2 3 cat3 1 sub1 This works without the validation process

How to display a form for a subset of associated records, some of which don't exist yet?

拈花ヽ惹草 提交于 2019-12-10 13:48:16
问题 I have Tasks and Users. When a user completes a task, I create a Completion which has a field for the user to indicate how long they spent. I need a form that shows all the tasks with their completion status and time_spent attribute. On submit, completions that existed should be updated and new ones should be created. I'd like to do this in Formtastic if possible but I'll be happy with a basic Rails 3 solution. class Completion < ActiveRecord::Base belongs_to :task belongs_to :user #