This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install in rails: config/initializers/to_b.rb | |
# | |
# Examples of how it makes things easier: | |
# | |
# true if [] # => true | |
# true if [].to_b # => nil | |
# true if "" # => true | |
# true if "".to_b # => nil | |
# true if 0 # => true | |
# true if 0.to_b # => nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/pick_first.rb in a rails app | |
class Object | |
# The pick_first function is a replacement for statements like users_value.present? ? users_value : default_value | |
# which using pick first can be replaced with pick_first users_value, default_value | |
# This is particularly helpful when you start getting into selecting the first out of three or more | |
# available values. | |
# | |
# pick_first "x", "y", "z" # => "x" | |
# pick_first nil, "y", "z" # => "y" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file goes in config/initializers | |
require 'bootstrap_form_builder' | |
# Make this the default Form Builder. You can delete this if you don't want form_for to use | |
# the bootstrap form builder by default | |
ActionView::Base.default_form_builder = BootstrapFormBuilder::FormBuilder | |
# Add in our FormHelper methods, so you can use bootstrap_form_for. | |
ActionView::Base.send :include, BootstrapFormBuilder::FormHelper |