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! While you're at it, check out some resources Treehouse students have shared here.

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

Display users posts on their profile

I am brand spanking new to rails & I've been stuck on this problem for awhile. I am trying to display the users posts on their profile. The problem I'm facing is that instead of the pictures being displayed it shows up as html code. Any help would be greatly appreciated!!!

Pics are showing up like this. Just text.

Post id: 13, description: "ME", created_at: "2014-06-19 19:29:10", updated_at: "2014-06-19 19:29:10", user_id: 1, image_file_name: "photo_copy.jpg", image_content_type: "image/jpeg", image_file_size: 110254, image_updated_at: "2014-06-19 19:29:09"

Here is my code:

class UsersController < ApplicationController

def show @user = User.find(params[:id])

      if @user 
    @posts = @user.posts.all
    render actions: :show
else
    render file: 'public/404', status: 404, formats: [:html]
end  

<% if @posts %> <%= @posts.each do |post| %> <%= post.inspect %> <% end %>

1 Answer

I got it finally!