Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a new record returns NoMethodError due to missing method that isn't being called
    primarykey
    data
    text
    <p>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:</p> <pre><code>**NoMethodError in StoriesController#create** undefined method `stack_id' for #&lt;Story:0x1035968a8&gt; </code></pre> <p>What's weird is that the create method makes no reference to 'stack_id'. In fact, it's pretty out of the box:</p> <pre><code>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 =&gt; @story, :status =&gt; :created, :location =&gt; @story } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @story.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <p>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.</p> <pre><code>map.resources :stories, :member =&gt; {:rate =&gt; :post} map.resources :anthologies map.resources :stacks, :has_many =&gt; :stories do |stack| stack.resources :stories end </code></pre> <p>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.</p> <p>Thanks.</p> <pre><code>Processing StoriesController#create (for 127.0.0.1 at 2010-11-17 21:45:29) [POST] Parameters: {"commit"=&gt;"save", "story"=&gt;{"body"=&gt;"sgfhsfgh", "title"=&gt;"asdfa", "user_id"=&gt;"1", "summary"=&gt;"adfgdfhg"}, "action"=&gt;"create", "authenticity_token"=&gt;"1yws3Fs108kPSUS2W5SM1GFaiRqfiWhDbzDWstfoDCA=", "controller"=&gt;"stories"} User Load (0.3ms) SELECT "users".id FROM "users" WHERE ("users"."id" = 1) LIMIT 1 NoMethodError (undefined method `stack_id' for #&lt;Story:0x1035968a8&gt;): (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) </code></pre> <p>Adding Model code by request, but it's pretty generic has_many :through...</p> <pre><code>has_many :anthologies has_many :stories, :through =&gt; :anthologies </code></pre> <p>and</p> <pre><code>has_many :anthologies has_many :stacks, :through =&gt; :anthologies </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload