Answers for "common functions in rails"

0

common functions in rails

# lib/my_utilities.rb

module MyUtilities
  def trim_string(string)
    do_something
  end    
end

#Then in controller or model where you want this:
# models/foo.rb

require 'my_utilities'

class Foo < ActiveRecord::Base
  include MyUtilities

  def foo(a_string)
    trim_string(a_string)
    do_more_stuff
  end
end
Posted by: Guest on March-02-2022

Browse Popular Code Answers by Language