Rails Paperclip result array index -


i try method avatar assets. user.rb code:

def get_avatar(size)  if self.assets.length != 0   self.assets.each |asset|     if asset.avatar      asset.photo.url(size)     end   end else   default_avatar(size) end 

end

in view:

user.get_avatar(:small) 

it should work in view have this:

 <img alt="jpeg&quot;, photo file size: 121649, photo updated at: &quot;2013 08 20 07:51:42&quot;, user id: 109, active: false, avatar: true&gt;]" src="/images/[#&lt;asset id: 176, created_at: &quot;2013-08-20 07:51:43&quot;, updated_at: &quot;2013-08-20 07:51:43&quot;, photo_file_name: &quot;user_2.jpg&quot;, photo_content_type: &quot;image/jpeg&quot;, photo_file_size: 121649, photo_updated_at: &quot;2013-08-20 07:51:42&quot;, user_id: 109, active: false, avatar: true&gt;]"> 

it doesn't take photo.url(size) whole array index.

when do:

rails.logger.fatal "check_me #{asset.photo.url(size)}" 

it return photo url. still doesn't work.

when :

self.assets.first.photo.url(size)  

it works. difference?

in get_avatar function, loop assets array, when asset's url, don't return it, function returns array itself. add return when url.

def get_avatar(size)    if self.assets.length != 0     self.assets.each |asset|       if asset.avatar         return asset.photo.url(size)       end     end   else     default_avatar(size)   end end 

hope helps.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -