On 5 August 2012 22:24, Steve Morrissey <[email protected]> wrote:
> Alright. Short and simple this time. Here is the code for
> snippets/show.html.erb (showing the article):
>
>                      <div class="span4">
>         <h1>Comments (<%= @snippet.comments.count %>)</h1>
>         <hr>
>         <% if signed_in? %>
>           <%= render 'shared/comment_form' %>
>         <% end %>
>         <% if @snippet.comments.any? %>
>           <%= render @comments %>
>         <% else %>
>         <p>There are no comments on this snippet.</p>
>         <% end %>
>       </div>
>
> Here is comment.html.erb being showed by render @comments:
>
> <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>
>
> That is the code that isn't working and is giving the error. The only
> thing that will display is comment.content.
>
> And here is the log output. Seems to be properly getting the user data
> for each comment, but comment.user isn't working. If I'm way off, let me
> know again. At the very least I'm learning to better communicate issues
> on this style of forum (sadly at the expense of peoples time).
>
>    (0.1ms)  SELECT COUNT(*) FROM "comments" WHERE
> "comments"."snippet_id" = 4
>   Rendered shared/_comment_form.html.erb (19.5ms)
>   CACHE (0.0ms)  SELECT COUNT(*) FROM "comments" WHERE
> "comments"."snippet_id" = 4
>   Comment Load (0.3ms)  SELECT "comments".* FROM "comments" WHERE
> "comments"."snippet_id" = 4 ORDER BY comments.created_at ASC
>   User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" =
> 14 LIMIT 1
>   User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" =
> 15 LIMIT 1
>   CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 14
> LIMIT 1
>   Rendered comments/_comment.html.erb (27.5ms)
>   Rendered snippets/show.html.erb within layouts/application (172.9ms)
> Completed 500 Internal Server Error in 21602ms
>
> ActionView::Template::Error (undefined method `email' for nil:NilClass):
>     1: <div class="comment_container">

Put some debug in here to display (or log) comment.inspect (see the
Rails Guide on debugging), and also comment.user.inspect unless
comment.user is nil.

Colin

>     2:   <%= 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>
>     3:   <div class="comment_content"><%= comment.content %></div>
>     4: </div>
>   app/helpers/users_helper.rb:7:in `gravatar_for'
>   app/views/comments/_comment.html.erb:2:in
> `_app_views_comments__comment_html_erb___715147692_2186695040'
>   app/views/snippets/show.html.erb:24:in
> `_app_views_snippets_show_html_erb__1112126603_2190824420'
>
> Colin Law wrote in post #1071379:
>> On 5 August 2012 21:48, Steve Morrissey <[email protected]> wrote:
>>> communication (which is even harder to grasp while viewing the
>>>>>
>>> of this yet. As a direhard PHP programmer, getting my mind into Rails
>>> When _comment_form.html.erb looked like that I was able to get comments
>>> displaying of comments to break, which is not associated.
>>> comment form broke the displaying of comments, though I'm sure its a
>>> fairly basic error I'm encountering. Especially since, on the comments
>>> partial, I'm still able to see the comment.content, just none of the
>>> comment.user (who made the comment) information.
>>
>> Sorry, much too much information again.  Don't complicate it by
>> telling us about which bits do work or used to work, just pick out the
>> bit of code that is not working and show us that.  Put debug code in
>> so that you can tell us what data is going in and explain what is
>> going wrong. We have not (or at least I do not) have time to wade
>> through all that information.  If you have multiple problems then
>> start off with just one of them.
>>
>> There will only be a dozen or so lines of code so just put it inline.
>>
>>>
>>> 1 beer for anyone who can help guide this lost soul :)
>>
>> I am doing my best, but you must keep the question simple.
>>
>> Colin
>
> --
> 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.
>
>

-- 
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