I am creating a simple ajax feature into my application where a user can increase a "like count" through a link.
I have managed to get the link to run my controller code and the browser is getting a response back, but the response is not executed.
The like link is in partial:
.likes
.like_up
= link_to( image_tag('/images/thumb_up.png'), '/like/' + question.id.to_s, :remote => true)
#like_count
= 22# question.likecount
.like_down
= link_to( image_tag('/images/thumb_down.png'), '/dislike/' + question.id.to_s, :remote => true)
And it goes into likes_controller:
def up
@like = current_user.likes.create( :question_id => params[:question_id], :like => true )
respond_to do |format|
format.js
end
end
Then in my up.js.haml I simply have a debug javascript:
alert('2');
and nothing else.
When I press the like link in browser the rails log tels me that it has rendered the js.haml
...
Rendered likes/up.js.haml within layouts/application (104.9ms)
Completed 200 OK in 923ms (Views: 116.3ms | ActiveRecord: 20.1ms)
And when I look at the response the browser gets it certainly looks like the up.js.haml rendered into my application layout where the yield tag is placed.
<div class='content'>
alert('2');
</div>
I suspect that this is not what the browser wants to get back. Also when looking at the firebug console during the ajax request, nothing happens after the request is sent.
Could someone find out why this is not working? Every tutorial and guide I have found does this the same way I'm doing here.