Upmin Admin Interface in Rails Composer

I’ve added the Upmin admin framework to Rails Composer as an option. Upmin is an admin dashboard similar to Active Admin or RailsAdmin. The upmin-admin gem is new and well-designed, from Upmin, a startup building customer support software.

Admin dashboards such as Upmin give you convenient access to your database, so you can search by any attribute, and view, update, or delete any records. The interface should only be used by an administrator since it lets you make any changes to your application data. Best of all, there’s no code to write and nothing to configure. The upmin-admin gem is a Rails engine, so you can override its controller and views if you want to customize your admin dashboard.

Rails Composer gives you an option to add Upmin when you select Devise for authentication with role-based authorization or Pundit. Rails Composer:

  • adds the upmin-admin gem
  • configures the application so only users with an admin role can access the admin dashboard
  • adds a navigation link to the application navbar

You can select Upmin when you generate the rails-devise-roles or rails-devise-pundit starter applications, or when you build a custom application using Devise with role-based authorization or Pundit.

The Upmin admin dashboard is a great addition to make Rails Composer even more powerful. It’s a new integration, and I haven’t tried it with every possible option in Rails Composer, so open an issue on GitHub if you discover anomalies.

As always, a big thanks to everyone who joins the RailsApps project with a subscription, supporting the project.

Role-Based Authorization

Recently I released an example application and tutorial showing how to use the Pundit gem for authorization. Pundit is great, but often it’s not needed. Many developers don’t realize that simple role-based authorization can be added to a Rails application with just a few lines of code.

I’ve released a new example application showing how to implement simple role-based authorization:

It’s available as a choice on the menu for Rails Composer, when you generate a starter application.


I’ve written an in-depth article comparing simple role-based authorization, Pundit, and the popular CanCan gem:


I’ve completed a new Role-Based Authorization Tutorial.

RailsApps subscribers are getting tutorials every month:

You can join RailsApps to get the tutorials and support the project.

Role-Based Authorization

The new tutorial covers role-based authorization, showing how to use the Active Record enum feature in Rails 4.1 to add a role attribute to a User model. You can set up roles for administrators, users with free or premium plans, or any other system of privileges. The tutorial shows how you can set up simple role-based authorization without any extra gems. For more complex applications, see the Pundit Quickstart Guide.

I appreciate the on-going support from RailsApps subscribers. If you like the articles, the tutorials, the example applications, or Rails Composer, please subscribe to support the RailsApps project.

Error Installing Rails 4.2.0.beta1

Rails 4.2.0.beta1 is out with some great new features such as Active Job. Unfortunately, there’s a bug with the newest 2.4.1 release of RubyGems (the system gem) that makes it difficult to install Rails 4.2.0.beta1. See Rails issue 16609.

Check if you are using RubyGems 2.4.1:

$ gem -v

Do you encounter this error when installing Rails 4.2.0.beta1?

$ gem install rails --pre
ERROR:  While executing gem ... (Gem::DependencyError)
    Unresolved dependency found during sorting - activesupport (>= 4.0)
(requested by sprockets-rails-3.0.0.beta1)

You can work around the problem by downgrading to the 2.2.2 version of RubyGems.

$ gem update --system 2.2.2
Updating rubygems-update
Fetching: rubygems-update-2.2.2.gem (100%)
Successfully installed rubygems-update-2.2.2
Installing RubyGems 2.2.2
RubyGems 2.2.2 installed

Now you will be able to install Rails 4.2.0.beta1.

If you are using RVM, and you want to use two different versions of the RubyGems system gem, you’ll need to install two different versions of the latest Ruby 2.1.2 release with different RVM names. For example, if you already have Ruby 2.1.2 installed with the newest RubyGems 2.4.1, you can install another version of Ruby 2.1.2, giving it a different name:

$ rvm install ruby-2.1.2-oldrubygem

RubyGems 2.2.2 is installed by default with the current Ruby 2.1.2 release:

$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
$ gem -v

You’ll be able to install Rails 4.2.0.beta1.

‘Learn Ruby on Rails’ Free for Students

Do you know someone who teaches a class or workshop on Rails?

I offer my book for beginners, Learn Ruby on Rails, to students enrolled in classes or workshops, including university and community college classes, immersive code camps, and community workshops. The book is popular with instructors and students. Here are some of the places where the students have received the book for free:

  • Rails Girls
  • RailsBridge
  • The Flatiron School (NYC)
  • New York Code & Design Academy
  • Code Fellows (Seattle)
  • MakerSquare (Austin and SF)
  • Makers Academy (London)
  • Portland Code School
  • Tech Talent South (Atlanta)
  • Brandeis University (Boston)
  • Griffith University (Australia)

If you know someone who teaches Rails, they can email me at daniel@danielkehoe.com for an evaluation copy of the book. For an independent review, see Tech Book Face Off: Learn Ruby on Rails. The book is free for students enrolled in any organized class or workshop. If you’re studying on your own, organize a study group and get in touch with me. Or purchase a RailsApps subscription for the book plus many more in-depth tutorials.

RailsApps Update for Devise 3.3

Devise 3.3 was released on August 13, 2014. The Devise CHANGELOG lists several minor enhancements and bug fixes. In the new version, Devise default views now say “Log in” instead of “Sign in.” Alex Soble proposed the change, based on an article that points out the easy confusion of “Sign up” and “Sign in.” What do you think? Was the change warranted?

Perhaps a more significant change is new wording for the error messages when a user’s email address or password is incorrect. If you’re using an application that includes feature tests for sign in (oops, “log in”) with Devise, and you update the Devise locale file, your feature tests will break. Take a look at the changed locale file if you’d like to see the new error messages.

Several of the RailsApps example applications use Devise and provide RSpec tests for sign up and sign in with Devise. I’ve updated the RailsApps example applications to use Devise 3.3 and revised the tests so they continue to work. The aim of the RailsApps project is to provide a reliable reference implementation for integration of the gems that developers are most likely to use in a new Rails application. With this update, you’ll get the most recent version of Devise when you use Rails Composer or copy an example application.

The RailsApps project is supported by our monthly subscribers. If you like the work we’re doing, please consider joining and supporting the project with a subscription.

Rails Bootstrap Update

Bootstrap 3.2 was released on June 26, 2014 and the bootstrap-sass gem was released immediately afterward. Bootstrap 3.2 contains many new features and bug fixes but the biggest impact for Rails developers are new installation instructions for the bootstrap-sass gem. Previously, developers added Bootstrap to the Rails asset pipeline by adding to the app/assets/stylesheets/application.css.scss file:

@import "bootstrap";

Now the recommendation is to use:

@import "bootstrap-sprockets";
@import "bootstrap";

This will only matter to you if you are using glyphicons. See details if you’d like to know more.

The installation instructions are also different for the Bootstrap JavaScript components. In the file app/assets/javascripts/application.js we had:

//= require bootstrap

Now we can use:

//= require bootstrap-sprockets

The older version delivered concatenated JavaScript. The newer version uses a require for all Bootstrap modules, making output easier to debug.

Most Rails developers who are using Bootstrap are unaware of these changes, unless they’ve recently reviewed the bootstrap-sass README. It’s an example of a typical open source problem. An obscure bug gets fixed by changing how a gem gets integrated into an application but developers don’t learn they need to update their applications to accommodate the fix. That’s where the RailsApps project provides a service. I’ve updated every RailsApps example application that uses Bootstrap, so if you clone a repository or use Rails Composer to create a starter app, you’ll have the correct configuration for Bootstrap. You can use the RailsApps example applications as a reliable reference implementation, so you can easily see how Bootstrap or other gems should be integrated with Rails.

Rails Authentication With OmniAuth

I’ve completed a new tutorial on Rails authentication with OmniAuth.

RailsApps subscribers are getting tutorials every month:

You can join RailsApps to get the tutorials and support the project.

OmniAuth Tutorial

I’ve already written a tutorial about Devise, the most popular authentication gem. With Devise, users sign up with an email address and password to gain access to your web application. With OmniAuth, visitors sign in using an account they already have with Twitter, Facebook, GitHub, or many other social networking sites. If you are building an application that is intended for users of one of these social networking sites, you’ll probably want to use OmniAuth, and the new tutorial shows you how.

In the tutorial, I first show a simple way to implement authentication. Then, in the chapter “Customizing the Application,” I show how to request an email address from the user when he or she first signs in to your application. Some service providers (Twitter, Meetup, LinkedIn) do not provide an email address when their users sign in to your application using OmniAuth. The lack of an email address can be a business drawback, if you want the opportunity to stay in contact with the user by email, so the tutorial shows how to solve the problem.

Analytics for Rails Composer

Now, when you build a Rails starter application with Rails Composer, you get the option of page-view tracking without any effort. Run Rails Composer and you’ll see:

recipe  Running analytics recipe...
option  Install page-view analytics?
    1)  None
    2)  Google Analytics
    3)  Segment.io
choose  Enter your selection: 2
option  Google Analytics ID?

You get a choice of either Google Analytics or the Segment.io service.

Google Analytics

With the release of Rails 4.0 and Rails TurboLinks, it’s been difficult to set up Google Analytics in a Rails application. Rails Composer solves the problem with a brilliant JavaScript implementation from Jonathon Wolfe. Rails Composer installs Jonathon’s tracking script in the Rails asset pipeline and sends tracking data to Google Analytics whether or not TurboLinks is enabled in your Rails application.


I like Segment.io because it gives me Google Analytics plus any of 107 other services. With Segment.io, you can instantly switch on tracking for services such as Mixpanel, KISSmetrics, and many others. It’s a commercial service but it’s free for low-traffic sites (less than 100K pageviews or events per month). Rails Composer installs the Segment.io tracking script in the Rails asset pipeline, and adds code to accommodate Rails TurboLinks.

Rails and Analytics

I wrote an article on Analytics for Rails last year. You can see the article for more about the code you need for analytics. My goal for Rails Composer is “no mystery code.” That’s why I write tutorials and articles to explain the code generated by Rails Composer. Thanks to support from RailsApps subscribers, I was able to update the article this week. Please join me in giving a shout-out of thanks to the subscribers who pay $19/month to make this possible. And if you haven’t joined, please consider getting a subscription to support the project.

Mailing List

There’s also a new mailing list for news about Rails Composer. Join the mailing list if you want announcements of new features for Rails Composer.

Mailing List for Rails Composer

You can now join a mailing list for news about Rails Composer. Sign up here:

Expect to receive two or three emails a month with announcements about features and changes.

The next time you run Rails Composer to build a starter application, you’ll see an option to join the mailing list. I’ve built an application for mailinglist.railscomposer.com (which you can find on GitHub) with a simple API that responds to a curl request generated by Rails Composer. It’s fun to see it in action. From the Rails Composer command line you can enter your email address, and the mailinglist.railscomposer.com application updates a MailChimp mailing list. Rest assured, there’s no funny business going on with the email addresses (it’s open source so anyone can examine the code); email addresses are not stored in the application database; they are simply passed to MailChimp.

I’m eager to see how many developers are using Rails Composer. In just a weekend, 20 developers have signed up for the mailing list. The Rails Composer repo on GitHub has over 2000 stars but we don’t really know how many developers are actively using Rails Composer. In any case, the mailing list will be a better channel than blog posts or tweets to announce Rails Composer features and changes.

If you’ve got ideas for Rails Composer, let me know. You can reach me at (daniel@danielkehoe.com). Thanks to support from subscribers, I’m now working full-time on the RailsApps project, splitting my time between developing Rails Composer and writing tutorials.

Locale Recipe for Rails Composer

Thanks to a code contribution by a developer in Russia, Rails Composer now has an option to set a default locale for a starter application. Anton writes, “I know it isn’t a significant new feature, but maybe the ability to set a default locale would be handy for developers from non-English-speaking countries.”

Rails Composer saves one step for a developer by setting the default locale in the config/application.rb file and creating an empty file in the config/locale/ folder. As a bonus, if the application uses Devise for authentication, Rails Composer will add the devise-i18n localization gem. That means your Devise messages are automatically translated for 40 different languages. Cool!

It would be nice if we could automatically translate the English words on the default Rails Composer home, user, and about pages. To do that, we’d have to add translations to the rails_apps_pages gem. That’s not in my plans, but if anyone wants to do it, I’ll add the contributed code.

Right now, the “set a default locale” option is available when you select “Custom application” in Rails Composer.

Next page Something went wrong, try loading again? Loading more posts