get carrierwave image based on certain conditions?

How could one get a carrierwave image with has certain condition?

For example:


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 ("/assets/avatars/img_96x96.png")

Is there a way to improve this? thx!


def show_avatar_thumb(id)
    user = User.find(id)
  rescue ActiveRecord::RecordNotFound
    image_tag ("/assets/avatars/img_96x96.png")
    image_tag true).first.file_url(:img_96x96)

I would pull where(main: true) out and put it in a model scope though.

Need Your Help

javascript done function without ajax call

javascript jquery ajax promise jqxhr

I want to make a function that supports done but without returning ajax.

JSTL escaping special characters

jsp escaping jstl special-characters

I have this weird issue with special characters.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.