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

Avatar link appears broken

I am on the adding avatars lesson, when I add an image tag after the file_field to show the image, it appears broken on the page when I try to upload an image (I am using rails 4).

#views/devise/registrations.edit.html.erb file:


<div class="form-group">
    <%= f.label :avatar %>
    <%= f.file_field :avatar, class: "form-control" %>
    <%= image_tag @user.avatar.url(:thumb) %>
  </div>


#user model:                                                                                                                                                               

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

has_many :logs

has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }

validates :name, presence: true

validates :username, presence: true
end

#Database migration:
                                                                                                                                            class AddAvatarToUsers < ActiveRecord::Migration
   def self.up
    add_attachment :users, :avatar
  end

  def self.down
    remove_attachment :users, :avatar
  end
end