Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

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
 
PREVIOUS NEXT
Tagged: #common #functions #rails
ADD COMMENT
Topic
Name
9+6 =