I'm honestly not even sure where to start with this problem but I've implemented a "like" feature on my site and when I'm looking at the console I see a REALLY REALLY long SQL statement.
I'm not going to post all of my dev.log because it's just INCREDIBLY long but here's a snippet of some of the errors..
Started POST "/recipes/1/like?like=true" for 127.0.0.1 at 2015-11-20 22:46:45 -0500
Processing by RecipesController#like as HTML
Parameters: {"authenticity_token"=>"b64tIveTCtassgzKoJ/d65c72b3DfLmkC1ddQrCRBsbxnAuKMYpnz8L/+m5SsJ8to57v4sFXSkLIZB9QdFXdTQ==", "like"=>"true", "id"=>"1"}
^[[1m^[[35mRecipe Load (0.1ms)^[[0m SELECT "recipes".* FROM "recipes" WHERE "recipes"."id" = ? LIMIT 1 [["id", 1]]
^[[1m^[[36mCACHE (0.0ms)^[[0m ^[[1mSELECT "recipes".* FROM "recipes" WHERE "recipes"."id" = ? LIMIT 1^[[0m [["id", "1"]]
^[[1m^[[35mCACHE (0.0ms)^[[0m SELECT "recipes".* FROM "recipes" WHERE "recipes"."id" = ? LIMIT 1 [["id", "1"]]
And then it just repeats that sql statement over ~10,000 lines and then it switches to this error
15008 app/controllers/recipes_controller.rb:46:in `like'
15009 app/controllers/recipes_controller.rb:46:in `like'
15010 app/controllers/recipes_controller.rb:46:in `like'
15011 app/controllers/recipes_controller.rb:46:in `like'
15012 app/controllers/recipes_controller.rb:46:in `like'
15013 app/controllers/recipes_controller.rb:46:in `like'
15014 app/controllers/recipes_controller.rb:46:in `like'
15015 app/controllers/recipes_controller.rb:46:in `like'
15016 app/controllers/recipes_controller.rb:46:in `like'
15017 app/controllers/recipes_controller.rb:46:in `like'
I'm kind of stuck and I was hoping someone could point in in the right direction.
Here's my code:
Controller
def like
@recipe = Recipe.find(params[:id])
Like.create(like: params[:like], chef: Chef.first, recipe: @recipe)
flash[:success] = "Your selection was successful"
redirect_to :back
end
Model:
class Like < ActiveRecord::Base
belongs_to :chef
belongs_to :recipe
end
I have the corresponding "has_many" in my other controllers"
Migration:
class CreateLikes < ActiveRecord::Migration
def change
create_table :likes do |t|
t.boolean :like
t.integer :chef_id, :recipe_id
t.timestamps
end
end
end
View:
<%= link_to like_recipe_path(@recipe, like: true), method: :post do %>
<i class="glyphicon glyphicon-thumbs-up"></i>
<% end %>