Alright so I changed my comment form snippet from:

<%= form_for(@comment, :html => { :class => "joinform" }) do |f| %>

To:

<%= form_for([@snippet, @snippet.comments.build]) do |f| %>

Which caused my comment form to finally work successfully, however the 
following code now fails (this is my comment snippet)

<div class="comment_container">
  <%= gravatar_for comment.user, :size => 30 %> <span 
class="username"><%= link_to comment.user.username, comment.user %> 
commented <%= time_ago_in_words comment.created_at %></span>
  <div class="comment_content"><%= comment.content %></div>
</div>

What does work about this is the comment.user and comment.created_at 
lines. Oddly enough, comment.content still shows the comment content. 
And comment.user.username still yields the users username, 
comment.user.email yields the commenters email, etc. However when 
passing comment.user into anything now fails.

NoMethodError in Snippets#show

Showing 
/Users/morri534/rails_projects/srclockr/app/views/comments/_comment.html.erb 
where line #2 raised:

undefined method `email' for nil:NilClass

I feel like I'm so close to getting a working comment system, but I'm 
missing one piece of the puzzle. I fixed the article comment box not 
working, but now the comments wont display the user info associated with 
them.

As usual, any help is greatly appreciated :)

Here is some more code if it helps any:

class SnippetsController < ApplicationController
  before_filter :signed_in_user, :only => [:create]
  ...
  ...
  def show
    @snippet = Snippet.find(params[:id])
    @user = User.find(@snippet.user_id)
    @comments = @snippet.comments
    impressionist(@snippet)
  end


class Comment < ActiveRecord::Base
  attr_accessible :content, :snippet_id, :user_id
  belongs_to :snippet
  belongs_to :user


class Snippet < ActiveRecord::Base
  attr_accessible :content, :title, :description

  belongs_to :user
  has_many :comments

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to