user2860931 user2860931 - 1 year ago 155
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

Can anyone see what's wrong?

Answer Source

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


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" 


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

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