I have a jQuery function called after double-clicking 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"); });
Along with applying some new formats to the specified element, my main goal is to record the database from my like controller. In this Railscast, the index action from their comments controller is invoked using this simple line.
$.getScript("/comments.js");
In addition, some JavaScript is called from the index.js.erb file.
My first problem with understanding Railscasts sample code is how they define an action. If I wanted to call the createLike action from my likes_controller , what would I call it?
Secondly, my attempts so far have not worked, because both JavaScript files are not loading, and the action is also not called.
Somehow I feel like I messed up the way. Where should I look for JavaScript files that should be called using the getScript function?
Files
application / assets / javascripts / likes / index.js.erb
console.log("Test");
application / 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
jquery ruby ruby-on-rails ruby-on-rails-3
TheCha͢mp
source share