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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:03:21+00:00 2026-05-25T23:03:21+00:00

So for some reason my code seems to have a mind of its own

  • 0

So for some reason my code seems to have a mind of its own and will work at some points and then other times will throw an error saying undefined name method when trying to run this code in the view

  <%= div_for comment do %>
   <p>
       <big><%= h(comment.body) %> - <%= link_to comment.user.name, comment.user %>   </big><br />
       Posted <%= time_ago_in_words(comment.created_at) %> ago
   </p>
 <% end %>

The code for my comments controller looks like this

   def create
     @post = Post.find(params[:post_id])
     @comment = @post.comments.build(params[:comment])
     @comment.user_id = current_user.id
     @comment.save
     respond_to do |format|
       format.html { redirect_to @post}
       format.js
       format.json { render :json => @comments }
     end
   end

Like I said sometimes this code works fine and sometimes it doesn’t. I’m not sure whats causing the problem, whats even more weird is that in my localhost its working fine but when I push the code to my domain it doesn’t work. Before you say it may be a domain rails version mismatch you should know this problem has occurred on my localhost as well before and then resolved itself magically without me changing any code. If anyone could help me it would be greatly appreciated.

Edit: Here is the error log you requested

 Completed 500 Internal Server Error in 286ms

 ActionView::Template::Error (undefined method `name' for nil:NilClass):
     1: <%= div_for comment do %>
     2:     <p>
     3:         <big><%= h(comment.body) %> - <%= link_to comment.user.name,  comment.user.name %></big><br />
     4:         Posted <%= time_ago_in_words(comment.created_at) %> ago
     5:     </p>
     6: <% end %>
   app/views/comments/_comment.html.erb:3:in `block in    _app_views_comments__comment_html_erb___3516162043769402279_2170426440__2165839557434581766'
   app/views/comments/_comment.html.erb:1:in     `_app_views_comments__comment_html_erb___3516162043769402279_2170426440__2165839557434581766 '
   app/views/posts/show.html.erb:14:in      `_app_views_posts_show_html_erb__667623582898069867_2171134300_136023206927572946'
   app/controllers/posts_controller.rb:23:in `show'
  • 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-25T23:03:21+00:00Added an answer on May 25, 2026 at 11:03 pm

    You may checkout the value of comment.user when the error occurs. It seems that comment.user is not an object User as you expect. Checkout your database, maybe some comments are not associated with users or associated with non-existant users.

    You can try to debug like this when you’ll have the error again:

    <% comments.each do |comment| %>
      <%= debug comment %> // Or comment.user
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code pasted below. For some reason, the response.redirect seems to
for some reason this code wont work, it doesn't seem to read the javascript.php
For some reason the following code doesn't work on Windows XP. new URL(file:// +
I have this while loop in my code. The loop seems to work fine
For some reason my code is just comment in my html. I have tried
I have some Python code with error handling in place but for some reason
For some reason my code here (this is the entire thing) doesnt actually render
preg_match(/\b(word1|word2)\b/iu, 'text text text word1 text text'); For some reason the above code doesn't
For some reason this line of code is giving me quite a problem. struct
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('

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.