#5 Florrick


This is a Rails library which integrates with Active Records and provides some awesome user-initiated string interpolations for your web apps. For example, have you ever needed to allow users to insert their own variables into e-mail templates or messages?
rails model strings 6:28


Gemfile  gem 'florrick'
Passing a block into the florrick method.

  class User < ActiveRecord::Base
    florrick do
      string :first_name, :last_name
      string(:full_name) { "#{first_name} #{last_name}"}
      string(:age) { Date.today.year - birthday.year - (birthday.to_date.change(year: Date.today.year) > Time.now ? 1 : 0)}

  # {{user.full_name}}
In the Rails console, we saw how the options are passed through Florrick.convert to interpret the strings and replace them with our dynamic content.

console  string = "Happy Birthday {{user.full_name}}."
  string = "Happy Birthday {{user.full_name}}. You are now {{user.age}} years old!"
  Florrick.convert(string, user: user)