Re: [Rails] Re: Simple (I'm sure) Question about Joins
On 5 August 2012 03:42, Steve Morrissey <lists@ruby-forum.com> wrote:
Since you have not quoted the previous message I have just wasted time
looking back through the thread to work out what this is about.
Remember this is a mailing list not a forum, though you may be using a
forum style interface
> 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
You appear to have provided lots of irrelevant information this time,
but not shown the code where the error is generated. I see that it is
in a partial, and that you are calling email on something that is nil.
Perhaps you have forgotten to pass the object to the partial.
Also have a look at the Rails Guide on debugging, which will show you
techniques that can be used to help in debugging the code.
Colin
>
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home