[英]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. 因此,我只想列出附有图片的厨师。
In HomeController 在HomeController中
@chefs = Chef.where({:status_id => [0,1]}).all(:order => 'created_at DESC', :limit => 10)
@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? 有没有办法将这种情况放在@chefs var中?
If don't... how can I do this? 如果没有,我该怎么办? I'm new in ruby/rails.
我是红宝石/导轨的新手。
Thanks! 谢谢!
You probably want this in HomeController: 您可能需要在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. 这将仅选择状态ID为0或1并且化身文件名不为null的厨师。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.