Tuesday, October 25, 2016

Rails and Draper Railscast Sample Code

To get the Railscast example code profile-before to work, change the Gemfile to lock the redcarpet version:

gem 'redcarpet', "~> 1.17.2"

Otherwise, you will get the error:

undefined method `new' for Redcarpet:Module

The newer version of Redcarpet requires new syntax to instantiate, refer: https://github.com/vmg/redcarpet/issues/231

To get the Railscast example code profile-after to work, use the following Gemfile:

gem 'rails', '4.2.4'
gem 'sqlite3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', '5.0.4'
  gem 'coffee-rails', '4.1.0'
  gem 'uglifier', '2.7.2'

gem 'jquery-rails', '4.0.5'
gem 'redcarpet', '3.3.3'

gem 'draper', '2.1.0'

Otherwise, you will install the latest gems that is not compatible with the code.

Focus Question : Is the Draper version 1.4 compatible with Rails 4.x ?

Readme does not mention what Rails version is compatible with Draper 1.4. There is a clue in the Gemfile:

version = ENV["RAILS_VERSION"] || "4.0"

which means it must be compatible. Let's downgrade the Rails sample project to draper version from 2.1 to 1.4 and see if it works. Uninstall all versions of draper and lock the draper gem version to 1.4 in the Gemfile.

gem 'draper', '1.4.0'

The profile page still works. So it seems that draper 1.4 is compatible with Rails 4.x.