Skip to content

Instantly share code, notes, and snippets.

@eostrom
Forked from anonymous/gist:4410050
Last active December 10, 2015 08:48
Show Gist options
  • Save eostrom/4410054 to your computer and use it in GitHub Desktop.
Save eostrom/4410054 to your computer and use it in GitHub Desktop.
Another way to simplify Disqus comments (cf http://www.mwdesilva.com/posts/65-let-s-disqus).
class DisqusablePresenter < Struct.new(:subject)
def disqus_id
dom_id(subject)
end
def to_s
# You'd probably need to include something to make the `render` helper available here.
render :partial => 'disqusable/disqus_thread', :locals => {:subject => self}
end
end
# In the view:
# <%= raw DisqusablePresenter.new(@post) %>
@bsodmike
Copy link

Since I started with the 'post-XX' format, if I switched to dom_id it results in a snake-cased result, i.e. 'post_XX'. Therefore, I'm going with

class DisqusablePresenter < Struct.new(:subject)
  def disqus_id
    "#{subject.class.to_s.downcase}-#{subject.id}"
  end

  def to_s
    ActionController::Base.helpers.render :file => 'app/views/disqusable/disqus_thread', :locals => {:subject => self}
  end
end

Rendering the file directly as it just cannot be located as a partial. YMMV in this regard. Thanks again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment