Saturday, 12 January 2013

first post at netengine!

Not the best I've ever done, but I had to write something... A ruby implementation of the OAuth2 protocol for third party roles, enjoy!

http://goo.gl/UbHxI

Saturday, 5 January 2013

extend vs include

I always make confusion, although I'm getting better, this should help:


module MainMod
  module SubMod
    def self.included(cls)
      puts "#{self} included in #{cls}"
      cls.extend ClassMethods
    end

    module ClassMethods
      
      def ext
        puts 'extended'
      end
  
    end
  
    def inc
      puts 'included'
    end

  end
end

class A
  include MainMod::SubMod # => MainMod::SubMod included in A
end

A.new.inc
A.ext

module Mod1
  inc MainMod::SubMod
end

class B
  inc Mod1 # => MainMod::SubMod included in Mod1 !!!(Mod1)
end

B.new.inc
# B.ext # does not exists, `ext` was extended on Mod1

Tuesday, 25 September 2012

Tuesday, 31 July 2012

Change the db with migrations on the fly

What if you want to add a column though the console with one line of code? (and you exactly know what this implies)
ActiveRecord::Migration.new.add_column :payments, :card_verification, :string, limit: 8
ActiveRecord::Migration.new.execute "full sql here"

Saturday, 14 July 2012

Coffescript rendering

The correct way to render html inside your XHR response in Rails.

  app.showFlashMessages('<%=j flash_messages %>')
  $('.booking').replaceWith( '<%=j render @booking %>' )
  app.myFunction( <%=raw array.map(&:to_json) %> ) # TODO: double check

Monday, 4 June 2012

backtrace_silencers to clean the development log from missing assets

# /config/initializers/backtrace_silencers.rb
Rails.backtrace_cleaner.add_silencer { |line| line =~ /lib\/action_dispatch\/middleware\/static.rb/ } if Rails.env.development?

This simple line will clean up your development log to something like this:

[FTL] 
ActionController::RoutingError (No route matches [GET] "/assets/ecoologic/rooms/room_tb.png"):
  actionpack (3.2.5) lib/action_dispatch/middleware/static.rb:62:in `call'

This is only in development (or test?) as you usually don't use the static middleware in staging or production.