I've got a jQuery function that is called after a doubleclick on a list item.
app/assets/javascripts/tile/tile.js
$('#list > li').dblclick(function(){
// styling
$(this).toggleClass('liked');
// pass ID to controller
var movie_id = $(this).attr("data-id");
$.getScript("/likes.js");
});
Next to applying some new formats to said item my main goal is to make a database entry from my like
controller. In this Railscast the index
action from their comments
controller gets called with this simple line.
$.getScript("/comments.js");
Additionally some JavaScript gets called from a index.js.erb
file.
My first problem with understanding the example code from Railscasts is how they define the action. If I wanted to call the action createLike
from my likes_controller
how would I call it?
Secondly, my attempts so far have all failed because both the JavaScript file doesn't load and the action doesn't get called aswell.
Somehow I sense that I've messed up with the paths. Where should I locate the JavaScript files that should get called with the getScript
function?
Files
app/assets/javascripts/likes/index.js.erb
console.log("Test");
app/controllers/likes_controller.rb
class LikesController < ApplicationController
protect_from_forgery
def index
Like.create(:user_id => current_user.id, :item_id => params[:id])
end
end