FAQ Database Discussion Community


Nested Comment body not being saved Ruby on Rails

ruby-on-rails,devise,nested-forms,nested-attributes
I'm banging my head on my desk trying to figure out why the comment is posting comment.body, but when I go into IRB body=nil and it won't display on App show page. The structure: Apps have many comments on their show page, along with a comment form. Apps View: <h3>Comments</h3>...

Generating dynamic child rows in Rails partial

ruby-on-rails,nested-attributes,railscasts,ruby-on-rails-4.2
I have implemented a nested attribute form using the nested attributes Railscast as a guide. As a result, the user can click an icon to dynamically add "child" rows to my view. Unfortunately, I can only make this work for the last icon in my view (illustrated here). This icon...

Trouble in RSpec test - saving parent record twice

ruby-on-rails,ruby-on-rails-4,activerecord,rspec,nested-attributes
I'm new at Rails programming, and my RSpec test is failing when trying to save nested records. The logs from the test suggest that ActiveRecord is trying to save the parent twice, which results in a silent database save failure. sign_up_spec.rb (sorry for the omission!) require 'rails_helper' RSpec.feature "Accounts", type:...

Rspec testing nested destroy action for follows model

ruby-on-rails-4,rspec,nested-attributes
I have researched and seen a similar question (Rspec: Testing nested destroy action) but was unable to get the solution to work for me. In the app I am working on, we have an Articles model and users can Follow Articles. I have used the acts_as_follower gem to implement this,...

rails nested attribute do not show in form

ruby-on-rails,nested-attributes
I added a nested attribute to my form, the fields for the nested attribute which is Education fields do not render, the other fields do. The relationships appear to be in order and the controller does too. Here is the code. Controller def new @profile = current_user.build_student_profile end def profile_params...

Django serve get-requests

django,get,nested-attributes
Hey guys I am a bit new in Django. What I want to achieve is a URL which I can access with a GET request from my app, passing some values along with it. I have a UserProfile model in Django which has a oneToOneField relationship to User. I want...

How to display data for nested objects in a check box in Rails?

ruby-on-rails,nested-attributes
I'm having this issue where I want to display the correct answer in a check box in Rails, to no avail. The structure is further complicated by the fact that my models are nested into one another so that Survey not only has_many, but also accepts_nested_attributes_for Questions and Questions has_many...

Model-independent Rails 4 file upload in dynamically loaded (nested) form field

ruby-on-rails,file-upload,nested-forms,nested-attributes,form-helpers
I'm looking for a way for simple image upload onto the file system so that the image is not stored in the database. I understand this step is rather easy, just using a file_input tag, however I have problems making it happen because of how my form is built. I...

Rails with nested resources redirect Edit/Update method to Create method

ruby-on-rails,redirect,ruby-on-rails-4,nested-attributes
Working on Rails with nested resources, got an issue when using Edit/Update method redireced to Create method. Below is my demo: Model class Model < ActiveRecord::Base has_many :lineitems, dependent: :destroy end class Lineitem < ActiveRecord::Base belongs_to :model end Routes #resources :lineitems #resources :models resources :models do resources :lineitems end Rake...

undefined method `each' for #

ruby-on-rails,ruby-on-rails-4,carrierwave,image-uploading,nested-attributes
I try to upload a file, with using CarrierWave, and the Image model is polymorphic. But i got the error as in the title, so here is my models: class Image < ActiveRecord::Base belongs_to :imageable, polymorphic: true mount_uploader :image, ImageUploader enum image_type: {icon: 1, title: 2, regular: 3, slider: 4}...

Require nested params

ruby-on-rails,nested-attributes
I have a Rails server with a RESTful API allows to create "communities" with "users". To create a community I POST a JSON like this: { "community": { "name": "community name" } } to /api/v1/communities. The problem is that "name" must be mandatory, so if in CommunitiesController I do... def...

Attribute a Row, Nested Below (How to Show Proper Relationship in Table?)

ruby-on-rails,dynamic,nested-attributes
This is the most difficult question I've come to in the past few months of starting my Ruby on Rails journey. It seems like many people would face it, but I can't find anything on the web that addresses this problem, which means my question is either insanely easy that...

Rails Nested attributes being duplicated

ruby-on-rails,ruby,nested-attributes
This problem has beaten me. I've been at it all weekend but can't figure out what is happening. When I create a new employee object, I also want to create multiple new ee_pay records using accepts_nested_attributes_for :ee_pay in my employee model. Creation of ee_pay records for new employees is dependent...

Rails scoped uniqueness constraint throws error when updating nested attributes

ruby-on-rails,ruby,nested-attributes,unique-constraint,updating
I have an application that creates pages, called campaign pages, from a selection of widgets that can be used to specify the layout of the pages. I'm working on the functionality to load and edit the contents of a campaign page, alter the contents, and update the relevant entries for...

Two nested form objects

ruby-on-rails,ruby-on-rails-4,nested,nested-forms,nested-attributes
I have two nested objects (Attachment inside Widget, Widget inside Lesson). Lesson > Widgets > Attachments Lesson > Widgets > Links Everything is fine, but if I click on "Remove attachment", and then I click on "Update Lesson", nested attachments in the widget are not removed. Is that because I...

Rails 4 retrieve nested attributes for display in an index.html.erb

image,ruby-on-rails-4,twitter-bootstrap-3,nested-attributes,home
Just looking to find out how to retirve nested images for display on my front page. I have no problems with a standard model but have been unable to find how to bring has_many nested attribute through. All my nested Forms work fine just have neglected the front end. eg....

Is it a good idea to use has_one nested attributes in rails?

ruby-on-rails,nested-attributes,has-one
Let's say if I have 3 models; Hotel, Resort and restaurant. Each model have similar attributes; title, description, facilities ...and so on... If I want every models have one location with attributes; Country, Province, City, address, Latitude and Longitude. Should I create location model and using has_one nested attributes or...

How to create a simple nested signup form?

ruby-on-rails,ruby,ruby-on-rails-4,nested-forms,nested-attributes
I'm really stuck. Is there anyone who could help? What am I doing wrong? How can I create a simple nested form? I have two models each with their own resources: Organizations and Members. An organization has multiple members and a member is only a member to one organization. How...

nested model attributes + wicked wizard form not working

ruby-on-rails-4,simple-form,nested-attributes,wicked-gem
I am making an app based on the railscast tutorial 346(Wicked gem) and 196(nested model). I am trying to combine these 2 together and I am stuck because strong param attributes are not saving. So my app goes like this: I have a user, work, and education model. user.rb: has_many...

Multi nested attributes with ActiveAdmin

ruby-on-rails,activeadmin,nested-forms,nested-attributes
Hey so I have three models: DataSet BrowseOption BrowseOptionData Similar to Ryan's railscasts (http://railscasts.com/episodes/196-nested-model-form-revised?view=comments) I want to have a double nested form except in ActiveAdmin. Here is my Active Admin form: form do |f| f.inputs "Data Set Info" do f.input :name f.input :display_name f.input :description f.input :cover_photo, :label => "Cover...

Rails getting data from nested attributes

ruby-on-rails,join,nested-attributes
I have three models: data_set.rb class DataSet < ActiveRecord::Base has_many :browse_options accepts_nested_attributes_for :browse_options, allow_destroy: true end browse_option.rb class BrowseOption < ActiveRecord::Base belongs_to :data_set has_many :browse_option_datas accepts_nested_attributes_for :browse_option_datas, allow_destroy: true end browse_option_data.rb class BrowseOptionData < ActiveRecord::Base belongs_to :browse_options has_one :tradesman end I want to be able to display all the tradesman...

Undefined Nested Attributes for nil:NilClass

ruby-on-rails,ruby,nested-attributes,cocoon-gem
Please help me fix this error: NoMethodError in Quantifieds#index undefined method `results' for nil:NilClass I am a novice so hopefully this will take you far less time and be far more pleasurable to solve. Full trace below I gave a lot of code because I don't know how deep the...

How to .count nested_attribute boolean?

ruby-on-rails,ruby,boolean,nested-attributes,sidebar
The nested attribute of quantifieds are results. In the results partial a User will checkoff if their quantified result is a :good thing or not. In the sidebar I want to .count how many good results the User has marked off to serve as a reference point of their success....

Has Many Through relationship with accepts nested attributes

ruby-on-rails,associations,nested-attributes,has-many-through
I understand that in order to use nested attributes I need to use a has many through relationship instead of a has and belong to many so I have the following set up: class Deed < ActiveRecord::Base has_many :deeds_title_abstracts has_many :title_abstracts, through: :deeds_title_abstracts end class TitleAbstract < ActiveRecord::Base has_many :deeds_title_abstracts...

Nested attributes in form not visible

ruby-on-rails,activeadmin,nested-attributes,formtastic
I'm likely missing something simple, but I've tried a number of things to no avail. I need to be able to edit an existing track (using ActiveAdmin) and save the record updating its exclusivity status. I have a Tracks model #app/models/track.rb: has_many :exclusivities, class_name: 'Exclusivity', dependent: :destroy accepts_nested_attributes_for :exclusivities attr_accessible...

fields_for not creating a record when making a new parent record

ruby-on-rails,forms,ruby-on-rails-4,nested-attributes,fields-for
I am trying to automatically create a child record (Participant) when I create a parent (Project) record. I can create the parent (Project) fine and, on other forms, I can create the child (Participant). I cannot seem to create the child (Participant) at the same time as the parent. I...

Display nested attributes together in view or index.html.erb

html,ruby-on-rails,ruby-on-rails-4,twitter-bootstrap-3,nested-attributes
I have a Product model with most of the attributes and a has_many relationship through to my Product_Images model. All of the updates, edits etc work like a charm but I'm having difficulty bringing data through to a front end bootstrap theme. What I'm trying to do is have the...

Create two interdependent models from one form in rails

ruby-on-rails,ruby,forms,nested-forms,nested-attributes
I have used a combination of answers from 21222015, 17572279, 2663141, and RailsGuide to try and get multiple interdependent models to be created from a form. In my application Users are used for authentication and Clinicians and Patients are models for the two different types of Users. Clinicians and Patients...

Finding specific database entries when using nested attributes in RoR

ruby-on-rails,ruby,nested-attributes
I'm using nested attributes in my Ruby on Rails app (4.0.2) such that survey has_many questions and accepts_nested_attributes_for questions and question belongs_to survey. The problem that I have run into is that when I only want to look at the questions that belong to a particular survey I get an...

Add Multiple Nested Attributes through checkboxes Rails 4 (maybe with multiple forms)

ruby-on-rails,forms,checkbox,nested-attributes,strong-parameters
3/13 UPDATE: I've made a small sample project with my models, controller logic and several form versions. I am building a form where a user can add "Tasks" and "Milestones" together. (ie. Task = 'Vacuum' is inside Milestone = 'clean House'). It's basically a Task/Subtask type model with the parent...

how to pass params to action#new (in a nested has_many association) via link_to

ruby-on-rails,forms,ruby-on-rails-4,nested-attributes,link-to
I have a cinema system where you can select a session and buy a ticket for that so I have a link_to: <td><%= link_to 'Buy', new_offer_path(:session_id => session.id) %></td> I have a model called offer and a model ticket, when the user press Buy it generates a Offer. this offer...