Hi,
On Dec 3, 2007 4:23 AM, TTDaVeTT
<dlynam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> 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:
> <h1>upload an avatar</h1>
> <% form_for(:avatar, :url => avatars_path,
> :html => { :multipart => true }) do |f| -%>
> <p>
> <label for="avatar">upload an avatar:</label>
> <%= f.file_field :uploaded_data %>
> </p>
> <p>
> <%= submit_tag ''Create'' %>
> </p>
> <% 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?
>
I don''t know anything about attachment_fu but it seems you should
adjust
your association to has_one or belongs_to.
> 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?
if @avatar
<%= image_tag ''default.jpg'' %>
else
...
end
However, it appears you may way to call it @avatars as I look at your find
code which will return a collection of Avatars. So I would actually do
something like this.
if @avatars.size == 0
<%= image_tag ''default.jpg'' %>
else
...
end
ActiveSupport in Rails also provides Array#empty? so it could be written:
if @avatars.empty?
> 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?
nil and false are the only false things in Ruby.
> <%= 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
> >
> HTH,
Michael Guterl
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---