I have an and users can login and view their own profile with a form to type in their status. What the user typed can only be seen by let say “his friends” right now, haven’t worked on that but “his friends” can’t see it. for example I run the up and without signing in I got to a user’s profile, without me signing in makes the app show the status the user typed and that’s when I get the error:
undefined method ‘content’ for nil:NilClass
here is my users controller:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@microsposts = @user.microsposts.paginate(:page => params[:page])
end
def create
@microspost = current_user.microsposts.build(params[:microspost])
if @microspost.save
flash[:success] = "Micropost created!"
redirect_to current_user
else
render 'home/index'
end
end
end
_microspost.html.erb:
<%= microspost.content %>
_microspost_form.html.erb:
<%= form_for @microspost do |f| %>
<!--<render 'error_messages', :object => f.object %>-->
<div class="field">
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
<% end %>
I’m stuck on this one I’m so frustrated, I’ve been working on an app daily from non til 4am, now I gotta stop 45mins early because I just can’t go on debugging this, it’s been 2 hours.
I appreciate the help guy and gals….
and here is part of show.html:
<% unless @user.microsposts.empty? %>
<table class="microposts" summary= "User microposts">
<%= render 'microspost' %>
</table>
<!--will_paginate @microsposts %>-->
<% end %>
<td class="sidebar round">
<strong>Name:</strong> <%= @user.username %><br />
<strong>URL:</strong> <%= link_to user_path(@user), @user %><br />
<strong>Microposts:</strong><%= @user.microsposts.count %>
</td>
<% if signed_in? %>
<table class = "front" summary="For signed in users">
<tr>
<td class="main">
<h1 class="micropost">What you doin?</h1>
<%= render 'microspost_form' %>
</td>
<td class ="sidebar round">
<%= render 'user_info' %>
</td>
</tr>
</table>
<% else %>
<h1>testing test</h1>
<% end %>
Try to replace
<%= render 'microspost' %>with<%= @user.microsposts %>if@user.microspostsis an objet of classMicropost<%= render :partial => 'microspost', :object => @user.microsposts %>otherwise