Hey everyone, so I am building a social network and am sing
attachment_fu for photo uploading purposes. I’ve gotten this
functionality to work fine. I can have users upload multiple photos
and display them all. Now what is causing me trouble is trying to
give each profile an avatar/picture and having this avatar replaced if
a user wants a different picture. I think I need to implement some
sort of exists? function, to check if a user has uploaded an avatar
and if not, display a default image.
Heres the code I have for the upload view for an avatar:
upload an avatar
<% form_for(:avatar, :url => avatars_path, :html => { :multipart => true }) do |f| -%>upload an avatar: <%= f.file_field :uploaded_data %>
<%= submit_tag 'Create' %>
<% end -%>But this creates a new object, and I want to overwrite the existing
object so that avatar images are not piling up in the database. Does
anyone know how to do this?
The second problem if anyone has time is that I want to display a
default avatar if an avatar has not been uploaded.
This is a function that is part of my view for avatars:
@avatar = Avatar.find(:all, :conditions => { :user_id =>
session[:user_id] })
Is it possible to use an if else statement and check this @avatar
object to see if anything is in there?
and if not display the default?
So I was thinking something like this, but this does not work:
if @avatar == 0 //some logic like this?
<%= image_tag ‘default.jpg’%>
else
<% for avatar in @avatar -%>
<%= image_tag(avatar.public_filename(:thumb)) %>
<% end %>
If anyone has any ideas, they would be greatly appreciated. Thanks,
Dave