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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:54:11+00:00 2026-05-30T12:54:11+00:00

Currently getting an undefined method and I am unsure how to fix this issue,

  • 0

Currently getting an undefined method and I am unsure how to fix this issue, been stuck on this for a while now. All help is much appreciated!

NoMethodError in Users#show

undefined method `comments' for nil:NilClass

Extracted source (around line #2):

1: <div class="CommentField">
2: <%= form_for ([@micropost, @micopost.comments.new]) do |f| %>
3: <%= f.text_area :content, :class => "CommentText", :placeholder => "Write a Comment..." %>
4: <div class="CommentButtonContainer">
5: <%= f.submit "Comment",

User Controller

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
    @school = School.find(params[:id])
    @micropost = Micropost.new
    @comment = Comment.new
    @comment = @micropost.comments.build(params[:comment])
    @microposts = @user.microposts.paginate(:per_page => 10, :page => params[:page])
  end
end

Comment Controller

class CommentsController < ApplicationController 
  def create
    @micropost = Micropost.find(params[:micropost_id])
    @comment = @micropost.comments.build(params[:comment])
    @comment.user_id = current_user.id
    @comment.save 
      respond_to do |format|
      format.html 
      format.js
    end
  end
end

Comment Form

<div class="CommentField">
<%= form_for ([@micropost, @micopost.comments.new]) do |f| %>
<%= f.text_area :content, :class => "CommentText", :placeholder => "Write a Comment..." %>
<div class="CommentButtonContainer">
<%= f.submit "Comment", :class => "CommentButton b1" %>
</div>
<% end %>
</div>
  • 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-30T12:54:13+00:00Added an answer on May 30, 2026 at 12:54 pm

    I hate to tell you this but you have a typo. You typed @micopost.comments.new instead of @micropost.comments.new. Correct that and it’ll fix this problem.

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

Sidebar

Related Questions

I am currently getting an undefined method for adding <% if current_user.vote_up?(@micropost) == true
Been googling this for a while and having no luck. I'm getting an NoMethodError
i am getting this undefined method for albums controller and model any solutions?... undefined
I don't know when it happened but I'm getting this error NoMethodError (undefined method
I am currently getting first day Of this week and last week values with
I'm currently getting all the Select elements that exist in a form with the
I'm using prepared statements and MySQLi, and am currently getting this error. PHP Catchable
I am currently working through this tutorial: Getting Started with jQuery For the two
This was working just fine, not sure what broke it, but now I'm getting
I am getting undefined method `member' error in my following code Pls tell where

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.