Thursday, July 24, 2014

undefined method ... path due to polymorphic_url

i came across this non meaningful error,
as it turn out to be a mis named params

example: mispelled params[:nam] for params[:name]

Friday, July 18, 2014

ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds)

it turn out there could be 2 reasons,

1. rails connection pool have reached and there might be zombie connection
2. mysql max_connections / max_user_connections may have reached

in most cases, its the first possibility.
ensure that you have set the connection pool to a much higher value,
to handle enough concurrent users at the same time

production:
  adapter: mysql2
  pool: 100

2nd issue is due to zombie connection which may lead filling up pool with undead connections.
add a config/initializers/db_connections.rb
with these code:
-----------------
Rails.application.config.after_initialize do
  ActiveRecord::Base.connection_pool.disconnect!

  ActiveSupport.on_load(:active_record) do
    config = ActiveRecord::Base.configurations[Rails.env] ||
                Rails.application.config.database_configuration[Rails.env]
    config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
    #config['pool']              = ENV['DB_POOL']      || ENV['MAX_THREADS'] || 5
    puts "pool size: "+config['pool'].to_s
    ActiveRecord::Base.establish_connection(config)
  end
end
-----------------
these should hopefully handle undead issue for db connections.

another fix is possible to fix network connection bug when writing to a disconnected connection.
------------------
response.stream.write data
#workaround hang stream due to client dc halfway: https://gist.github.com/njakobsen/6257887
sleep 0.0001
-------------------

to check number of active connections for a database,
run rails dbconsole# (makesure you have set RAILS_ENV to the correct environment)
#and:

SHOW FULL PROCESSLIST;

thanks to these articles:


Wednesday, June 25, 2014

Circular dependency detected while autoloading constant

When face upon this issue,
its caused by naming controller or calling model name incorrectly.

possible issue are naming are case sensitive.
example:
#model
class Oi


end

But calling
OI.find #this lead to circular dependency error

Tuesday, May 20, 2014

Spree new.before?

Spree has nifty callbacks for controller,
create.before
create.after
update.before,
but what about new.before?

new_action.before :method_name

Monday, March 24, 2014

[atpvbaen.xls].WorkDay replaced

[atpvbaen.xls].WorkDay has been replaced by Application.WorksheetFunction.WorkDay in office 2010

Wednesday, March 19, 2014

work around for FB.XFBML.parse

For what ever reason due to reason update or facebook changes,
the god damn FB.XFBML.parse stop working...

found a work around:
if you are using fbml, eg:
[div id="mylike" class="fb-like" data-href="http://www.facebook.com/example"][/div];

#reload all fb like iframe:
function reloadFB() {
 FB.XFBML.parse();
 var boxes = jQuery(".fb-like iframe");
 for(var c=0; c < boxes.length; c++) {
  var box = boxes[c];
  box.src=  box.src;
 }
}