Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:28:01+00:00 2026-06-15T14:28:01+00:00

I’m aiming to implement a one-to-many -> one-to-many structure like the one described in

  • 0

I’m aiming to implement a one-to-many -> one-to-many structure like the one described in the rails api here:

class Document < ActiveRecord::Base
  has_many :sections
  has_many :paragraphs, :through => :sections
end

class Section < ActiveRecord::Base
  belongs_to :document
  has_many :paragraphs
end

class Paragraph < ActiveRecord::Base
  belongs_to :section
end

I’m trying to let the paragraphs class have a file upload through carrierwave, as described in the railscast on the topic, within a nested AJAX form that lets me add and remove sections and paragraphs.

Since I will be viewing the pictures only within the full document, I’m trying to keep the code within my Document controller. So, right now, the controller there is:

  def show
    @document = Document.find_by_username(params[:documentname])
    @section = @document.sections
#   @paragraph = @section.paragraphs #DONT UNDERSTAND WHY UNCOMMENTING THIS DOESNT WORK.
  end

Both my document and section models have the accepts_nested_attributes_for set up. However, when I load a document view, if I uncomment the @paragraph above, I get an error that suggests section assignment was successful, but paragraph assignment was unsuccessful for lack of a method:

NoMethodError in DocumentController#show
undefined method `paragraph' for #<ActiveRecord::Relation:0x007f9b6409c340>

If I comment it out, it appears to load the section assignment fine. Currently, my sections and paragraph tables are completely blank because I can’t set up the forms, so maybe that is part of the problem. But I think nil would give me a different error than no method, right? So, I suspect something is wrong under the hood already.

So, my main bits of confusion here: How and where do I construct a form controlled by my document controller to accept any data, and then especially to work with the carrierwave file upload?

If you have any other suggestions on how to structure this better, I’d appreciate it.

Also, what would be a good way to go about debugging this? I seem to be missing a method, which one, where?

I’ve referenced these, but wasn’t able to find a solution:

  • http://railscasts.com/episodes/196-nested-model-form-revised
  • http://railscasts.com/episodes/253-carrierwave-file-uploads
  • Carrierwave upload with nested forms?
  • Rails 3 + JQuery-File-Upload + Nested Model
  • Rails 3 and a Nested jQuery File Upload Model

Update 1

I suspect the problem is coming from my bad show commands? It can’t multi-index the right sections to the right paragraphs? So,

  def show
    @document = Document.find_by_username(params[:documentname])
    @section = @document.sections
#   @paragraph = @section.paragraphs #DONT UNDERSTAND WHY UNCOMMENTING THIS DOESNT WORK.
  end

should be more like:

  def show
    @document = Document.find_by_username(params[:documentname])
    @section = @document.sections
    @paragraph = @section.find(params[:section_id]).paragraphs
  end

This doesn’t work, but something like that? There’s a way it doesn’t seem to be linking the sections to the individual paragraphs. The error I get with the above is:

ActiveRecord::RecordNotFound in DocumentController#show

Couldn't find Section without an ID

Update 2

Maybe that means I should telescope all of the show commands? ie, that getting the right paragraphs for the right section would be covered more like so:

in the document controller:

def show
    @document = Document.find_by_username(params[:documentname])
    @section = @document.sections
end

in the section controller:

def show
    @section = Section.find(params[:id])
    @paragraph = @section.pictures
end

So, if that is the case, how do I set up my nested form? To jointly create (1) sections, (2) paragraphs, and (3) images in the railcasts-style ajax interface from within document#show page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:28:02+00:00Added an answer on June 15, 2026 at 2:28 pm

    None of the SO answers I searched for worked for me, because the initial key did not exist at the time of upload, so it was impossible to link to it.

    So, my solution was just not to try this design. Make a different form with less nesting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.