Can't get an article summary?

This works fine:

<% blog.articles.each_with_index do |article, i| %>
  <h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
  <%= article.body %>
<% end %>

This throws an error:

  <h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
  <%= article.summary %>
<% end %>

Something about that summary…

TypeError: type mismatch: String given
	/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:110:in `=~'
	/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:110:in `default_summary_generator'
	/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:98:in `summary'
	/Users/bob/Dropbox/Web Development/Projects/Middleman/BRP/source/index.html.erb:11:in `block (2 levels) in singleton class'

and so on…

Here’s the part of my config.rb concerning the blog gem:

activate :blog do |blog|
  # This will add a prefix to all links, template references and source paths
  # blog.prefix = "blog"

  # blog.permalink = "{year}/{month}/{day}/{title}.html"
  # Matcher for blog source files
  blog.sources = "posts/{year}-{month}-{day}-{title}.html"
  # blog.taglink = "tags/{tag}.html"
  # blog.layout = "layout"
  blog.summary_separator = "==="
  blog.summary_length = 250
  # blog.year_link = "{year}.html"
  # blog.month_link = "{year}/{month}.html"
  # blog.day_link = "{year}/{month}/{day}.html"
  # blog.default_extension = ".markdown"

  blog.tag_template = "tag.html"
  blog.calendar_template = "calendar.html"

  # Enable pagination
  blog.paginate = true
  blog.per_page = 10
  blog.page_link = "page/{num}"
end

# activate :directory_indexes

And my gemfile:

source 'http://rubygems.org'

# Middleman Gems
gem "middleman", "~> 4.1.0"
gem "middleman-blog"
gem "middleman-livereload"
gem 'middleman-autoprefixer'

# gem 'redcarpet', '~> 3.3', '>= 3.3.3'

# For feed.xml.builder
gem "builder", "~> 3.0"

Where have I gone wrong?

I don’t use the summary feature, but…

Did you check that you have === in your blog text? If you’re missing that, that might be the issue.

Otherwise, you need to give it more params, like

<%= article.summary(250, '>>') %>

as per the documentation.

1 Like

I do have the === in the blog text. I’m want to use that separator instead of a number of characters so that I can pick with the break will be.

@jng5 Wait! I have the separator in many articles, but not all!!!

When I added a separator to the articles without, it works!

Thanks so much for the clue that got me to a solution.

To use the summary length you need the nokogiri gem. That may be what was throwing up the error.