The behavior you're wanting is different than what that specific Railscasts is addressing. It is specifically focused on the retrieving of new comments as they are created, without a page refresh. That is why you are running into issues following this guide.
First you will need to make sure you have a resources :likes
in your config/routes.rb. From your code excerpt it looks like you are associating a like with a movie so make sure you make the route nested inside your resources :movies
call. In the end your routes should look something like this:
resources :movies do
resources :likes
end
For the controller piece you will need to add a 'create' action to your controller. Assuming that your Movie model has_many :likes
this is a simple version of what your action should look like:
def create
movie = Movie.find(params[:movie_id])
movie.likes.create(user_id: current_user.id)
end
You will also need to change your javascript code to make a post instead of a get request. That's because the http method is how Rails differentiates between a create and an index request as they both use the same url path (e.g. /comments.js). You will also need to have the url reflect that it's a nested resource within a movie. Here is modified version of your JS code with that change:
$('#list > li').dblclick(function() {
// Cached jquery this selector.
$this = $(this)
// pass ID to controller
var movie_id = $this.data('id');
$.post('/movies/' + movie_id + '/likes.js', function() {
$this.toggleClass('liked');
});
});
In regards to your .js.erb file, as stated by others, it should be placed in your app/views
folder. However, due to your regular JS handling the logic you don't need to have it all.
This is just one strategy but there are quite a few other ways to handle JS interaction with Rails. If you want an example of using a js.erb (js.coffee in this case) view file you can take a look at this implementation. In that case all that is handling the click event is a link_to with the remote: true option which delegates it the jquery-ujs adapter.
Hope that helps!