nested-forms

Nested model not available in Devise views

好久不见. 提交于 2019-12-11 23:50:18
问题 I'm having a problem with associations not being available in my views. My models are: :user has_many :subscriptions :subscription belongs_to :user I'm using Devise to manage authentication etc. for Users What I'd like to do: when creating a new user in the registration process, I also want to also create a subscription for that user. Since Devise::RegistrationsController#new by default does not initialize an associated subscription, I've created my own RegistrationsController : class

Edit Form Delete's a record from the database

…衆ロ難τιáo~ 提交于 2019-12-11 22:59:55
问题 I Have a nested form that works pretty well in saving content to the database. The only problem is that when I click edit, the "grand-child" field is deleted from the database and thus I have to re-enter everything on that field. The normal behavior is on editing the previous content should be present. I am using gem cocoon for nested forms simple_forms for my forms and ckeditor for richtext editing. This is the server log when I click edit: notice: SQL (0.3ms) DELETE FROM "responses" WHERE

Failing to store nested attributes values for models in rails (rails recipes 36)

≯℡__Kan透↙ 提交于 2019-12-11 19:19:16
问题 I am trying to store the value for each level i add, the number of fields visible gets updated as they should when i use add/remove buttons, but when i press submit only the game name gets stored. The scores are discarded somehow. <h1>Editing game</h1> <% flash.each do |name, msg| -%> <%= content_tag :div, msg, class: name %> <% end -%> <!--START--> <%= form_for @game do |f| %> <%= f.label :name %> <%= f.text_field :name %> <h3>Scores:</h3> <%= f.fields_for(:levels) do |level_form| %> <!--<%=

Rails 4 nested attribute in a form not saving

北城以北 提交于 2019-12-11 19:18:32
问题 I am trying to build a nested form in rails 4. I've got the view up and running however when I submit the form the values do not save to my database. I read through the following answer and tried to replicate it in my code but I am still having the same issue: Rails 4 nested attributes not saving Here are what I think the relevant pieces of code: View: <div class="field"> <%= f.label :imagefile %><br> <%= f.text_area :imagefile %> </div> <%= f.fields_for :amount_due do |ff| %> <div class=

How to create nested form in Ruby on Rails?

孤街浪徒 提交于 2019-12-11 18:38:00
问题 I have following arragement The Pizza model, to create a list of pizzas that can be ordered by customers, also gets associated with order, so to indicate which pizza has been ordered. class Pizza < ActiveRecord::Base has_many :pizza_orders has_many :orders, :through => :pizza_orders has_and_belongs_to_many :toppings end Option model, to create a list of options that can be associated with certain pizzas, also gets associated with the join table for each pizza order, to specify which pizza has

nested form display error

喜你入骨 提交于 2019-12-11 18:01:59
问题 I have the following form declaration for a new kindergarten <%= form_for @kindergarten, :html => {:multipart => true} do |f|%> <%= render 'shared/error_messages', object: f.object %> </br> <%= f.fields_for :photos do |p| %> <%= p.label 'upload photo'%> <%= p.file_field :image %> <% end %> </br> <%= render 'about_company', f: f%> </br> <%= render 'contact', f: f %> <%= f.submit "Create my account", class: "btn btn-large btn-primary" %> <%end%> The logic behind this is that 1 kindergarten can

Rails 4 Nested form with devise logs me out on update

坚强是说给别人听的谎言 提交于 2019-12-11 11:37:25
问题 I have a nested form with the parent model built with devise and the child model without devise. I'm working on the edit form which has the user model fields and nested inside them expert model fields. The update/save works but logs me out and gives me an error saying "You need to sign in or sign up before continuing" When I sign back in I see that the fields have been updated correctly. I would like it to not sign me out and show me the updated Edit page upon submitting the form. User model

fields_for for nested attribute returns nothing

﹥>﹥吖頭↗ 提交于 2019-12-11 06:25:52
问题 I'm trying to create a nested model form in Rails 3.0.3. Here are my models: class Bird < ActiveRecord::Base has_one :taxon, :as => :organism accepts_nested_attributes_for :taxon end class Taxon < ActiveRecord::Base belongs_to :organism, :polymorphic => true end Here's the controller method: def new @bird = Bird.new @bird.build_taxon end And here's the form: New Bird <% form_for @bird do |f| %> <p> <%= f.label :wingspan %> <%= f.text_field :wingspan %> </p> <p> <%= f.label :body_length %> <%=

adding a text input field through js or jQuery when clicking on another input field in rails 3

前提是你 提交于 2019-12-11 05:58:46
问题 I'm building a nested form in rails 3.1 and instead of pressing the "add" button i want to automaticly add an input field when typing text in an empty input field (just like making a question in facebook and adding poll options). But i also want to only add a field if there are characters typed in the field if the characters are removed the extra field should also be removed. I am working with rails 3.1 and so jQuery and jquery-rails are included in my gem, i don't know coffee script yet. 回答1

Rails: Couldn't find nested resource with ID

人走茶凉 提交于 2019-12-11 05:53:17
问题 I have a 3 layers nested model: galleries -> has many albums -> has many photos When I try to add a new album from here http://localhost:3000/galleries/1/albums/new I am getting "ActiveRecord::RecordNotFound in AlbumsController#create Couldn't find Gallery with 'id'=" Albums model: class Album < ApplicationRecord belongs_to :gallery has_many :photos accepts_nested_attributes_for :photos Gallery model class Gallery < ApplicationRecord has_many :albums accepts_nested_attributes_for :albums end