get carrierwave image based on certain conditions?
How could one get a carrierwave image with has certain condition?
Returns the first image but what If I want something like
@photo = Photo.where(:attachable_id => 1, :attachable_type => "Profile", :main => true)
:main => true means this is the profile picture a user has selected.
Also on a side note,
I have this function wich is a mess:
def show_avatar_thumb(id) @profile = User.find(id).profile rescue nil image_tag @profile.photos.first.file_url(:img_96x96) rescue image_tag ("/assets/avatars/img_96x96.png") end
Is there a way to improve this? thx!
def show_avatar_thumb(id) begin user = User.find(id) rescue ActiveRecord::RecordNotFound image_tag ("/assets/avatars/img_96x96.png") else image_tag user.profile.photos.where(main: true).first.file_url(:img_96x96) end end
I would pull where(main: true) out and put it in a model scope though.