This is my first question to Stack Overflow.
I'm writing a rails app which will be running in Heroku. User can like / unlike posts. This action is registered by recommendable gem's Sidekiq workers.
I'm using Public Activity to track activities of posts, hence a.trackable.id is the post.id...
I have the ajax call in following code working in localhost :
public_activity/posts/_create.html.erb :
<%= link_to "Beğenmekten Vazgeç", unlike_post_path(a.trackable.id), data: {id: a.trackable.id, toggle_text: 'Beğen', toggle_href: like_post_path(a.trackable.id)}, class: 'like_toggle', remote: true %>
in my Posts Controller :
def like
@post = Post.find(params[:id])
current_user.like(@post)
if request.xhr?
render json: { id: @post.id }
else
redirect_to user_profile_path(@post.user)
flash[:notice] = "Ajax hatası"
end
end
and _create.coffee file is
$(document).on 'ajax:success', 'a.like_toggle', (status, data, xhr) ->
$("a.like_toggle[data-id=#{data.id}]").each ->
$a = $(this)
href = $a.attr 'href'
text = $a.text()
$a.text($a.data('toggle-text')).attr 'href', $a.data('toggle-href')
$a.data('toggle-text', text).data 'toggle-href', href
return
essentially, it changes the like / dislike text as described in this question.
In my gemfile, I have
gem 'jquery-rails', '~> 4.0.3'
and in my application.js file I have ;
//= require jquery
//= require jquery_ujs
//= require jquery-ui
I cleaned and precompiled assets in production.
It is working OK in localhost. But in Heroku, I can't seem to get it working.
Here's the server log :
Processing by PostsController#like as HTML
Parameters: {"id"=>"1"}
User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Post Load (1.6ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT 1 [["id", 1]]
Redirected to https://emoportal.herokuapp.com/user_profiles/1
2015-04-24T16:14:15.287Z 3 TID-osdy24n1g Recommendable::Workers::Sidekiq JID-986cd2fea4f7bfffd55849b0 INFO: start
2015-04-24T16:14:15.368Z 3 TID-osdy24n1g Recommendable::Workers::Sidekiq JID-986cd2fea4f7bfffd55849b0 INFO: done: 0.082 sec
User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Completed 302 Found in 680ms (ActiveRecord: 6.7ms)
Any help or ideas will be much appreciated. Thanks.