Ask A Question


You’re not receiving notifications from this thread.

Forum Series episodes ... no method error: undefined method

Miguel asked in Rails

I've been following along the Forum series of episodes, when I try to submit a forum post, I get an error. It seems that the controller has trouble assigning the user id to the current user. I thought my associations were wrong, or had a typo but I tried to litteraly copy-paste Chris's code from the Github repo and nothing. What the hell is going on??

user model

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :forum_threads
  has_many :forum_posts

forum threads model

class ForumThread < ActiveRecord::Base
  belongs_to :user
  has_many :forum_posts
  has_many :users, through: :forum_posts

  accepts_nested_attributes_for :forum_posts

  validates :subject, presence: true
  validates_associated :forum_posts

I also tried scratching the through: :forum_posts and the whole has_many :users, through: :forum_posts... nope

forum posts model

class ForumPost < ActiveRecord::Base
    belongs_to :user 
    belongs_to :forum_thread    

The part of the ForumThreadsController that seems to raise the problem

        def create 
        @forum_thread = forum_thread_params
        @forum_thread.forum_posts.first.user_id =

            redirect_to @forum_thread 
            render action: :new 
[Here's the repo](
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 78,890+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.