user2860931 user2860931 - 7 months ago 73
Ruby Question

Rails 4 - Setting up Disqus

I'm trying to make an app in Rails 4.

I've added the discus-rails gem to my gem file and added the following to my application.js:

//= require disqus_rails


I've updated the layout with:

<%= disqus_init %>


I've added the following to my view:

<%- disqus_thread %>


I also tried:

<%= disqus_thread %>


(in case the first variation was an error in the gem documentation).

When I try all of this, I get this js console error:

ReferenceError: Can't find variable: disqus_rails
(anonymous function)privket:283
firejquery-1.9.0.self-03a8409f8b5892a2a0083af9807d4ffee4ac3118828c5ce5ad9edc49bf241316.js:1017
fireWithjquery-1.9.0.self-03a8409f8b5892a2a0083af9807d4ffee4ac3118828c5ce5ad9edc49bf241316.js:1127
readyjquery-1.9.0.self-03a8409f8b5892a2a0083af9807d4ffee4ac3118828c5ce5ad9edc49bf241316.js:416
DOMContentLoadedjquery-1.9.0.self-03a8409f8b5892a2a0083af9807d4ffee4ac3118828c5ce5ad9edc49bf241316.js:92


Can anyone see what's wrong?

Answer

Lets make sure everything is set up correctly. I went through and configured a test application based on the documentation with no issues.

Gemfile

gem 'disqus_rails'

Now bundle install

Create an initializer disqus_rails.rb (as described in the documentation):

DisqusRails.setup do |config|
  config::SHORT_NAME = "your_short_name"
  config::SECRET_KEY = "your_secret_disqus_key" 
  config::PUBLIC_KEY = "your public_disqus_key" 
  config::ACCESS_TOKEN = "your_access_token" 
end

application.html.erb

<head>
  <title>Tester</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= disqus_init %>
  <%= csrf_meta_tags %>
</head>

Your view file

<%- disqus_thread %>

Now start your server and things should work. Be sure to check the order of what is required in your application.js and also order of tags within your application.html.erb