Skip to content

Instantly share code, notes, and snippets.

@mcavallo
Last active December 29, 2015 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcavallo/7591616 to your computer and use it in GitHub Desktop.
Save mcavallo/7591616 to your computer and use it in GitHub Desktop.
class Course < ActiveRecord::Base
def image_or_default
image.empty? ? 'default.jpg' : image
end
end
@mostafahussein
Copy link

i tried this as a helper, i was testing on user before my student class model and it worked , is this the same concept ?

def avatar_url(user)
avatar_url = user.avatar? ? user.avatar.url : "user_avatar_small.png"
end

and inside the view : <%= image_tag avatar_url(user) %>
what is needed to make your code work ? i have an avatar column in my user model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment