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

  • Home
  • SEARCH
  • 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 699655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:24:37+00:00 2026-05-14T03:24:37+00:00

I’ve been having some difficulty in understanding the source of a problem. Below is

  • 0

I’ve been having some difficulty in understanding the source of a problem.
Below is a listing of the model classes. Essentially the goal is to have the ability to add sentences to the end of the story, or to add stories to an existing sentence_block. Right now, I’m only attempting to allow users to add sentences, and automatically create a new sentence_block for the new sentence.

class Story < ActiveRecord::Base
  has_many :sentence_blocks, :dependent => :destroy
  has_many :sentences, :through => :sentence_blocks

  accepts_nested_attributes_for :sentence_blocks
end

class SentenceBlock < ActiveRecord::Base
  belongs_to :story
  has_many :sentences, :dependent => :destroy
end

class Sentence < ActiveRecord::Base
  belongs_to :sentence_block

  def story
    @sentence_block = SentenceBlock.find(self.sentence_block_id)
    Story.find(@sentence_block.story_id)
  end
end

The problem is occurring when using the show method of the Story. The Story method is as follows, and the associated show method for a sentence is also included.

Sentence.show

def show
  @sentence = Sentence.find(params[:id])
  respond_to do |format|
    format.html {redirect_to(@sentence.story)}
    format.xml  { render :xml => @sentence }
  end
end

Story.show

def show
 @story = Story.find(params[:id])

 @sentence_block =  @story.sentence_blocks.build
 @new_sentence = @sentence_block.sentences.build(params[:sentence])

 respond_to do |format|
   if @new_sentence.content != nil and @new_sentence.sentence_block_id != nil and   @sentence_block.save and @new_sentence.save
     flash[:notice] = 'Sentence was successfully added.' 
     format.html # new.html.erb
     format.xml  { render :xml => @story }
   else
     @sentence_block.destroy
     format.html
     format.xml  { render :xml => @story } 
   end
 end
end

I’m getting a “couldn’t find Sentence_block without and id” error. So I’m assuming that for some reason the sentence_block isn’t getting saved to the database. Can anyone help me with my understanding of the behavior and why I’m getting the error? I’m trying to ensure that every time the view depicts show for a story, an unnecessary sentence_block and sentence isn’t created, unless someone submits the form, I’m not really sure how to accomplish this. Any help would be appreciated.

edit, the view:

<p>
  <b>Title:</b>
  <%=h @story.title %>
  <% @story.sentence_blocks.each do |b| %>
  <% b.sentences.each do |s| %>
    <br />
    <%=h s.content %>
    <% end %> 
  <% end %>
</p>

<% form_for @new_sentence do |s| %>
 <p>
   <%= s.label :sentence %><br />
   <%= s.text_field :content %>
 </p>
  <p>
   <%= s.submit "Create" %>
  </p> 
<% end %>

<%= link_to 'Edit', edit_story_path(@story) %>
<%= link_to 'Back', stories_path %>
  • 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-05-14T03:24:37+00:00Added an answer on May 14, 2026 at 3:24 am

    ruby-debug will be very helpful:

    gem install ruby-debug
    script/server --debugger
    

    Add the following after setting the @story in your show method:

    def show
     @story = Story.find(params[:id])
    
     debugger
     @sentence_block =  @story.sentence_blocks.build
    

    Then go to /stories/1 or whatever id you’re using to test, the page will not finish loading, go to the terminal you’re using for your server and you will see an irb prompt. You can run arbitrary code from that prompt and you can step through your code. Very useful.

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

Sidebar

Ask A Question

Stats

  • Questions 412k
  • Answers 412k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, I think the Soot framework performs escape analysis. May 15, 2026 at 7:59 am
  • Editorial Team
    Editorial Team added an answer Other folders are for different sorts of shared libs. For… May 15, 2026 at 7:59 am
  • Editorial Team
    Editorial Team added an answer Check your Itemid GET parameter in the URL. My guess… May 15, 2026 at 7:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.