Customize view scaffolding template using Bootstrap 5 Rails Custom View Scaffold Example Customize view scaffolding template using Bootstrap 5 We will do in this example: – Create new new the Ruby on Rails project using version 6.1.1 – Locate Railties path – Customize the scaffold template – Add Boostrap version 5.0.0-beta1 – Generate scaffold for category and article – Run project and… Read More
Highlighting text in Ruby 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
Rails UUID 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