I have some code to display my recipes in order of their popularity as shown below. This is stored in my index file for the recipe view.
<% @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 %>
As you can see I have passed a method 'this_week' which works perfectly defined as a scope.
My issue is, I have a tag cloud on the same page and when I click on a tag is should refresh the page but showing only those recipes with the associated tag.This works perfectly WITHOUT the this_week method applied but if the method is there I get the following error:
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
Any thoughts? Much appreciated.
You must have a created_at
field in both the recipes and tags tables. MySQL doesn't know which one it should order by. Where ever you are doing the ordering (in the this_week scope or in the tag method) you need to change this:
order('created_at')
to this:
order('recipes.created_at')
Assuming you want to order by the recipe's field. And if you don't like hardcoding the table name you can use self.class.table_name
and substitute that in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With