Wednesday, January 13, 2016

gem install mysql -v 0.3

ive issues with rails 4.1 that it does not play well with mysql2 v 0.4 .
im forced to use mysql2 v 0.3.20

when i ran gem install mysql -v 0.3.20
i came to this error:

errmsg.h is missing

ive already had mysql-dev installed.
after searching around, i found the issue.
cpanel mysql-config is still using mysql 5 dev library.
when i ran which mysql-config, and mysql-config, ive gotten cpanel 3rd party bin with v5.


so i renamed cpanel own mysql-config, and relink the correct mysql-config to cpanel/bin
mv /usr/local/cpanel/3rdparty/bin/mysql_config /usr/local/cpanel/3rdparty/bin/mysql_config5

ln -s /usr/bin/mysql_config /usr/local/cpanel/3rdparty/bin/mysql_config

reran gem install and bundle, and it works great now!


Sunday, January 10, 2016

rails admin date time input format

after upgrading to rails admin 0.8.1,
took me few hours trying to figure why all my datetime input fail to work.

it turned out that rails admin have forced their datetime input format based on
en.time.formats.long
this can be set in en.yml

otherwise, you may set the datetime by declaring in the configuration, etc:
field :created_at do
    date_format do
      :short
    end

end


for more formats:
http://apidock.com/ruby/DateTime/strftime


Monday, January 4, 2016

capistrano is slow, alternative: blazing

capistrano seems to be quite slow to deploy. it works great for production, as it export entire git into independent directory and relink directory from shared directory.

In some of my smaller projects,  i would prefer to maintain only 1 folder, and do a git hard reset and push the update directly from my local git.
my work around is to use blazing. since blazing 0.5, recipes is no longer supported.
blazing by default works great! but until you realize you are using spring, and passenger

ive customize blazing with spring generated bin removed from bin.

https://github.com/u007/blazing

to deploy:
  1. create to $HOME/rails/shared
  2. upload shared/config/application.yml (for figaro)
  3. mkdir shared/log
  4. mkdir shared/public/uploads
  5. mkdir shared/public/system
  6. mkdir shared/tmp
  7. mkdir shared/vendor/bundle

next, in your project,
  1. blazing init
  2. edit config/blazing.rb
    rake :"server:deploy"
  3. copy this file to lib/tasks/
    http://pastebin.com/13cTyvGg #if you use mod passenger
  4. blazing setup production
    # this will deploy git after deploy scripts on server
  5. blazing update production # to update later if changed blazing config

to deploy updates, simply:
  1. git push production master # remote: production, local branch: master

Sunday, December 27, 2015

undefined method `register_preprocessor' for nil:NilClass

seems to occur on sprocket-rails v3.0 sprockets-rails (2.3.3) works great! sprocketrails 2.3.3 + sprockets (3.5.2) it was due to less-rails https://github.com/rails/rails/issues/22647

Wednesday, November 25, 2015

dbflow raw query

As example:

class Abc {
public static String get_latest_updated_at(Class model, String where, Object... args) {
    ColumnAlias[] alias = new ColumnAlias[1];
    alias[0] = ColumnAlias.columnRaw("max(updated_at) as updated_at");

    String query = "select max(updated_at) as updated_at from "+FlowManager.getTableName(model);

    Cursor cursor = FlowManager.getDatabaseForTable(model).getWritableDatabase().rawQuery(query, null);
    if(cursor.getCount() > 1)
        return "";
    cursor.moveToFirst();
    return cursor.getString(cursor.getColumnIndex("updated_at"));
}


}

calling example:
Abc.get_latest_updated_at(Address.class, "")

//where by Address is model extending BaseModel

Monday, November 23, 2015

undefined local variable or method `try_spree_current_user'

If you create your custom spree controller,

beware that you will need to add in some spree controller helper to make the magic works

include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Store
include Spree::Core::ControllerHelpers::Order

or

you may extends from Spree::BaseController