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 3391252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:47:01+00:00 2026-05-18T03:47:01+00:00

I’ve been working on a project with a has_many :through relationship between a Story

  • 0

I’ve been working on a project with a has_many :through relationship between a Story and a Stack model, joined by Anthologies. I recently tweaked something that has broken the create method for new stories, but I’m not sure how to troubleshoot it. When I go to add a story, I get the following error:

**NoMethodError in StoriesController#create**
undefined method `stack_id' for #<Story:0x1035968a8>

What’s weird is that the create method makes no reference to ‘stack_id’. In fact, it’s pretty out of the box:

def create
  @story = Story.new(params[:story])

  respond_to do |format|
    if @story.save
      flash[:notice] = 'Story was successfully created.'
      format.html { redirect_to(@story) }
      format.xml  { render :xml => @story, :status => :created, :location => @story }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @story.errors, :status => :unprocessable_entity }
    end
  end
end

I thought maybe it had something to do with the routes, as they support accessing stories both directly and nested in stacks. But I’ve tried a number of variations and nothing seems to make a difference.

map.resources :stories, :member => {:rate => :post}  
map.resources :anthologies
map.resources :stacks, :has_many => :stories do |stack|
  stack.resources :stories
end  

I’m clearly not understanding something about how objects are getting saved here. Any ideas on how I can solve this problem? I’m completely lost on what to do next. I’ve added the console output below in case it’s helpful.

Thanks.

Processing StoriesController#create (for 127.0.0.1 at 2010-11-17 21:45:29) [POST]
  Parameters: {"commit"=>"save", "story"=>{"body"=>"sgfhsfgh", "title"=>"asdfa", "user_id"=>"1", "summary"=>"adfgdfhg"}, "action"=>"create", "authenticity_token"=>"1yws3Fs108kPSUS2W5SM1GFaiRqfiWhDbzDWstfoDCA=", "controller"=>"stories"}
  User Load (0.3ms)   SELECT "users".id FROM "users" WHERE ("users"."id" = 1) LIMIT 1

NoMethodError (undefined method `stack_id' for #<Story:0x1035968a8>):
  (eval):13:in `send'
  (eval):13:in `scope_condition'
  app/controllers/stories_controller.rb:58:in `create'
  app/controllers/stories_controller.rb:57:in `create'

Rendered rescues/_trace (90.0ms)
Rendered rescues/_request_and_response (0.3ms)
Rendering rescues/layout (internal_server_error)

Adding Model code by request, but it’s pretty generic has_many :through…

has_many :anthologies
has_many :stories, :through => :anthologies

and

has_many :anthologies
has_many :stacks, :through => :anthologies
  • 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-18T03:47:01+00:00Added an answer on May 18, 2026 at 3:47 am

    Based on your routes I’d expect your stories table has a stack_id and the model has something like:

    class Story < ActiveRecord::Base
      belongs_to :stack
      ..
    end
    

    Do you have a stack_id field in the stories table?

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

Sidebar

Related Questions

No related questions found

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.