Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Can't get statuses to appear on profiles controller

I am currently on the "testing the profiles controller" exercise on "building a simple ruby on rails app" learning adventure.

I am having a problem because when I write the code to display the "statuses" (In my application I call them logs) it displays the html or the console information instead of the proper front end display with the image, and bootrap customization.

here is what is displayed when I run my app:

Log id: 1, description: "einstein", created_at: "2013-11-26 06:09:06", updated_at: "2013-11-26 06:09:06", user_id: 1, image_file_name: "93434191-einstein-tongue_custom-36fb0ce35776dc2d92e...", image_content_type: "image/jpeg", image_file_size: 52317, image_updated_at: "2013-11-26 06:09:03"

Here is the code I wrote in the profiles/show page:

<div class="page-header"> <h1> <%= @user.username%> </h1> </div>

<% @logs.each do |log| %> <%= log.inspect %> <% end %>

the log.content command doesn't work for me like in the lesson.

Any help would be appreciated!

4 Answers

Casey Clayton
Casey Clayton
16,708 Points

Well keep in mind that you are displaying the output of the log.inspect there, that is where you are getting the output posted above. When you really want to see the content of the log. You say that .content isn't working here, which I am not sure why, can you post what happens if you do use the .content on log instead of inspect. This method still works in Rails 4 so there really isn't any reason it shouldn't be working.

Also keep in mind all your styling aspects such as <div> tags etc should all be inside the <% @logs.each do |log| %> <% end %>

For example with bootstrap classes for styling, you would do.

 <% @statuses.each do |status| %>
  <div class="container">
    <div class="status">
      <div class="row">
        <div class="col-md-7">
          <b><%= status.user.full_name %></b>
          <p><%= status.content %></p>
        </div>
       </div>
      </div>
     </div>
    <% end %>

Hi Casey,

I am getting a NoMethodError

 undefined method `content' for #<Log:0x007f96d5872be8>
Casey Clayton
Casey Clayton
16,708 Points

What this means is that your log object is uninitialized. Check in your log_controller.rb file and see if you have something like the following. (I used status in the example just change it to your object name.) The @objectname = Object.new is what you need to make sure it is initializing the object.

def new
    @status = Status.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @status }
    end

I added the initializer like so to my log_controller.rb file:

def new
    @log = Log.new
    @log = current_user.logs.build
  end

but still no luck :/

btw happy thanksgiving! lol

Casey Clayton
Casey Clayton
16,708 Points

Hm that's odd. The only reason I can think that it would be throwing that error is because it isn't being initialized properly. If you have posted this to github could I get a link? If not could you possible upload it so I could download the source and see if I can come up with a solution that way.

Hi casey,

sorry for the delay, as I was out of the country with no internet access. I still have not figure out the problem, here is the link to my github:

https://github.com/AliciaTGlenn/TanglyMane