【发布时间】:2014-02-07 02:43:17
【问题描述】:
我有一些代码可以按如下所示的受欢迎程度来显示我的食谱。这存储在我的食谱视图的索引文件中。
<% @all_recipes.this_week.reorder("likes_count DESC").limit(10).each do |i| %>
<%=link_to image_tag(i.image(:fixed), alt: "MUC", :class => "browse-recipes"), i %>
<% end %>
如您所见,我通过了一个方法“this_week”,它完美地定义为一个范围。
我的问题是,我在同一页面上有一个标签云,当我点击一个标签时,应该刷新页面,但只显示那些带有关联标签的食谱。如果没有应用 this_week 方法,这可以完美地工作,但如果该方法是否出现以下错误:
SQLite3::SQLException: ambiguous column name: created_at: SELECT "recipes".* FROM "recipes" JOIN taggings recipes_taggings_81e277c ON recipes_taggings_81e277c.taggable_id = recipes.id AND recipes_taggings_81e277c.taggable_type = 'Recipe' AND recipes_taggings_81e277c.tag_id = 33 WHERE "recipes"."live" = 't' AND (created_at > '2014-01-13 00:00:00.000000') ORDER BY likes_count DESC LIMIT 10
有什么想法吗?非常感谢。
【问题讨论】:
标签: ruby-on-rails scope ambiguous