简体   繁体   中英

PAPERCLIP: How to list only users who have a image attached?

I have the "paperclip" working in my app.

So, I want to list only chefs who have a image attached.

  • ruby 1.9.2p290
  • rails 3.1.1

In HomeController

@chefs = Chef.where({:status_id => [0,1]}).all(:order => 'created_at DESC', :limit => 10)

In Home Index view

<% @chefs.each do |chef| %>
  <%= image_tag chef.avatar.url(:thumb), :height => '50', :width => '50' %>
<% end %>

Is there way to put this condition in @chefs var?

If don't... how can I do this? I'm new in ruby/rails.

Thanks!

You probably want this in HomeController:

@chefs = Chef.where({:status_id => [0,1]}).where('avatar_file_name is not null').all(:order => 'created_at DESC', :limit => 10)

That will select only chefs whose status id is 0 or 1 and whose avatar file name is not null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM