Highlighting text in Ruby ### Start code def highlight(text,search_string) keywords = search_string.squeeze.strip.split(” “).compact.uniq matcher = Regexp.new( ‘(‘ + keywords.join(“|”) + ‘)’ ) highlighted = text.gsub(matcher) { |match| “<b>#{match}</b>” } return highlighted end text = “This is an example of the text.” search = “example text” puts highlight(text,search) # => This is an <b>example</b> of the… Read More

UUID’s I love UUID’s. You should use them. Rails 4 makes it simple to get setup and use UUID’s throughout your project. First, we enable UUID’s: rails g migration enable_uuid_extension This creates the following migration: class EnableUuidExtension < ActiveRecord::Migration def change enable_extension ‘uuid-ossp’ end end Next, create a model rails g model Book title The… Read More