rubychan / coderay

Fast and easy syntax highlighting for selected languages, written in Ruby.
http://coderay.rubychan.de/
Other
845 stars 115 forks source link

ActionView::Template::Error (Symbol or String expected, but NilClass given.) #219

Open ldco2016 opened 6 years ago

ldco2016 commented 6 years ago

Today I started to get this error after I uploaded my latest blog:

ActionView::Template::Error (Symbol or String expected, but NilClass given.)

I noticed I only got the error when I was signed in as admin.

I looked at my heroku logs which referenced code that was tied to my admin_actions partial:

<div class="blog-post">
    <h2 class="blog-post-title"><%= link_to blog.title.upcase, blog %></h2>
    <p class="blog-post-meta">Published <%= distance_of_time_in_words(blog.created_at, Time.now) %> ago</a></p>

    <!-- <%= render partial: 'blogs/admin_actions', locals: {blog: blog} %>

    <p><%= markdown blog.body %></p> -->

 </div><!-- /.blog-post -->

but the logs also references:

2017-11-21T22:43:24.204407+00:00 app[web.1]: F, [2017-11-21T22:43:24.204360 #4] FATAL -- : [58b9a24b-3a61-4e43-8e61-c92eb08c5258] app/helpers/blogs_helper.rb:8:inblock_code'`

which is: CodeRay.scan(code, language).div

inside the block_code method inside of CodeRayify class:

module BlogsHelper
    def gravatar_helper user
        image_tag "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user.email)}", width: 60
    end

    class CodeRayify < Redcarpet::Render::HTML
        def block_code(code, language)
            CodeRay.scan(code, language).div
        end
    end

    def markdown(text)
        coderayify = CodeRayify.new(filter_html: true, hard_wrap: true)

        options = {
            fenced_code_blocks: true,
            no_intra_emphasis: true,
            autolink: true,
            lax_html_blocks: true,
        }

        markdown_to_html = Redcarpet::Markdown.new(coderayify, options)
        markdown_to_html.render(text).html_safe
    end

    def blog_status_color blog
        'color: red;' if blog.draft?
    end
end

I was wondering if this was a known error or if someone can assist me to identify if CodeRay.scan(code, language).div is no longer a valid way to write this.