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

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 "";
    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


you may extends from Spree::BaseController

Friday, October 23, 2015

authorize! for update

just realize calling model.update after authorize! is wrong!

the right way is to run an authorize!, then model.assign_attributes, then rerun authorize! again, 
and finally

Tuesday, October 20, 2015

running rvm based cron job

rvm is requires a bash login to work.
in order to execute cron jobs, run this:

*/5 * * * * 'sh /home/myuser/versions/current/'

create a shell file,
change working directory to rails root,
and run the required job, such as delayed_job once and exit

vi /home/myuser/versions/current/
cd /home/myuser/versions/current
/bin/bash -l -c 'RAILS_ENV=production bundle exec rake jobs:workoff'

Thursday, October 1, 2015

speeding up vagrant and virtualbox synced folder on mac and windows

first, use nfs for sync folder,

in Vagrantfile:
web.vm.synced_folder "/private/var/www", "/var/www", type: "nfs", mount_options: ['rw', 'vers=3', 'tcp', 'fsc', 'actimeo=2']

actimeo=2 # increases speed of file sync

then do a: 
vagrant reload

On Windows:
web.vm.synced_folder "c:/wamp/www", "/var/www", type: "smb"

Notes: nfs on windows is not fully compatible. On linux guest machine, it does not allow file locking. This isn't good enough with rails, especially. Smb is an good option with file locking support, and fast response time. But this requires running command prompt as administrator to start smb command.

Hope it helps ;)

Friday, August 28, 2015

installing volley for android

Latest volley is available in maven repository,
therefore, you do not need to compile volley from source code.
goto Build > Library and dependencies > dependencies
click + add, search for volley

If you insists:
---old stuff---
Follow instruction here:

but first, makesure you have setup your environment and paths:


export ANDROID_HOME=/path-to-android-sdks

(Please change the path-to-android-sdks and gradle version accordingly)

for windows, you may use SET instead of export.
example: set PATH=%PATH%;...


instead of using ant to build, use `gradle build`.
didnt work for me, i tried to use android studio to open the project, and did not manage to get it compiled...

Thursday, July 30, 2015

connecting to sql server with rails

sql server / sql express is by default cannot be connected by a fixed port
to login to sql server, first, assign a password for sa user,
or any user, and map the database to the user.
you may use db_owner for default role mapping.

then open sql configuration manager
select sql server netwrok configuration > Protocols for localhost / express / your instance name
select TCP/IP
scroll to bottom, and set:
all ports: 1433
dynamic port: (empty, not even a zero)
then goto control panel > services > sql server
restart service,
enable sql browser (auto start delayed) and start service

this shall help to make it work with rails or tiny_tds

Monday, July 20, 2015

mariadb 10.0 upgrade from 5.5

Upgrading to Mariadb10 seems to fail on my ubuntu 14 virtualbox.
What i did was restart the instance,
followed instruction from:

and prompt to replace my my.inf configuration with maintainer configuration.
but it still failed.
tail -n 200 /var/log/syslog turn out that it was unable to bind at

so i vi /etc/mysql/my.inf
change the binding address to

and it works :)

Tuesday, July 7, 2015

exim smarthost matching null or empty string via wildlsearch

okay, it took me a long time to finally figure how to match possible null / empty string
due to nature that sender_address_domain may be empty if its a bounce mail,
delimiting it in a string did not work, turn out ive to just create a blank {}

client_send = : ${extract{auth_name}{${lookup{${if eq{$sender_address_domain}{}{'default'}{$sender_address_domain}}}nwildlsearch{/etc/smart}{$value}fail}}} : ${extract{auth_pass}{${lookup{${if eq{$sender_address_domain}{}{'default'}{$sender_address_domain}}}nwildlsearch{/etc/smart}{$value}fail}}}

with this, it matches in /etc/smart:

default: auth_name=... auth_pass=...

notice the {} empty without any string inside

other complaints:
- for some weird reason, strlen function wont work in section: auth...

Monday, May 25, 2015

executing apm with atom on windows

If you have installed atom via chocolatey,
the default path to apm for atom is located in


Thursday, May 21, 2015

deploying to production via capistrano with passenger and sub uri

due to digested assets requirement in production environment,
the url of images cannot be use in relative to path to css file.

example normal assets:

example of digested assets


due to this, the only way to accurately point to images in css is to add relative path to the url.
one way todo it is to use ENV['RAILS_RELATIVE_URL_ROOT'],
first, you will need to change .css file to .css.erb.
and add in <%=ENV['RAILS_RELATIVE_URL_ROOT']%> to the url path.
example: background-image: url('<%=ENV['RAILS_RELATIVE_URL_ROOT']%>/img/logo.png');

but since we are precompiling via capistrano, it is a must to add this environment into deploy/production.rb
set :bundle_flags, '--deployment' # set this to ensure traces of assets compilation can be shown via --trace
set :default_env, {

and then run:
cap production deploy --trace

took me hours to try to figure all the issues in place to resolve this.
hope it helps you :)

Thursday, April 30, 2015

iis 7 and rails

after struggling to get things running,
i finally found my best solution.


If you are running iis 8, just use httpplatformhandler, it save you a lot of time. but you will need to get webmatrix running. but this is not supported on iis 7/7.5, a bummer :(


so moving on to try microsoft web platform.

also several issues,
webmatrix does not play well with proxy, ke-damn!

Some odd / weird results when trying to install webmatrix,
first, it requires iis express, and ive no idea why do it need it.
but after running install and it failed, we are still able to open the webmatrix installer options.
Just ignore the webmatrix installation issue.

webmatrix and proxy?

setting http proxy in environment does not help in one of my client case,
you might want to consider setting up this: - works like a charm for me :)

Okay, please please please do not install helicon method. Their ruby and rails are outdated!
This will save you the hassle from installing old ruby 1.8 and 1.9 on your machines. And this may conflict with railsinstaller ruby.

So, what now? how do we run rails on /rails uri?
Yes, install Application Request Routing (ARR).
Inside webmatrix, search for arr, install it :)
After install, restart your iis manager (not refreshed if you have it opened while installing).

Okay, unless you want to setup entire host to proxy to another port, dont setup ARR on root level.

In my case, ive setup uri "/rails" to proxy over to my own rails instance.
Todo so, create a application "rails" under Default sites.
Then click into rails, and click on "Rewrite rules".
Then "Add rule" > "Reverse proxy"
Key in "" for server name,
After adding, double click on the rules, and ensure that you have similar configuration alike below. Notice the {R:1} appended as suffix of the rewrite url.

Setting up Rails + Ruby

to setup ruby, goto (thank god engine yard started something for us).
makesure to install with devkits and git and ssh.
it makes life much easier.
It will install to c:\RailsInstaller
all the paths should have been set for you, thank god :)

Then next, you might realize your gem install throws sslv3 certificate error with, another bummer. It turn out as of today 30th april 2015, certificate has been renewed on rubygems but it wasnt updated to the trusted repository of gems.
Follow here:

Since im using 2.1.5, ive followed to 2.0.15 instruction (not sure why the 2.0).

Download the .gem, and runs:
gem install --local rubygems-update-2.0.15.gem
update_rubygems --no-ri --no-rdoc

you may run:
gem update (to test if it works)

You will realize latest rails is already installed by railsinstaller.
Create a new app to try
c:\Sites\rails new app1

then create a startup file (this is using webrick, best to replace using either puma or thin)
@echo off
set RAILS_ENV=production
set SECRET_KEY_BASE=yoursecretkeyshere
rails s

and edit
and change `run Rails.application` to:
map "/rails" do
  run Rails.application

map "/" do
  run Rails.application

Notice the uri rails is used to indicated a uri so that all proxy over from iis can be used with this uri.

Installing Mysql2 gem

ensure your mysql2 gem is 0.3.18 or later

install the connector of your platform and 32/64bits (install the installer if you want to use path below)

next, run:
path to connector: C:\Program Files\MySQL\MySQL Connector C #version
example: v6.1
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\Program Files\MySQL\MySQL Connector C 6.1"'

Gems requirements on windows

Due to bugs and issues on windows, these are the min require versions of gem if you need to use them on windows:

gem 'eventmachine', '>=1.0.7'
gem 'bcrypt', '>= 3.1.10'
gem 'mysql2', '>=0.3.18'

Thursday, April 16, 2015

solr and pint

solr 5 no longer support p prefixed fieldtype,
pint, pstring, pdate, etc... no longer supported.

solr query rows did not return all results

solr by default allows query
*:* and x=1

but it is not suppose to make sense if you are adding condition,
*:* should not be added.
but solr allows to return all results to match x=1.

but when use with edismax,
the results seems to return strange behaviour as it does not return all rows.
therefore, removing *:* does the tricks in use_dis_max = true is used.

Monday, March 16, 2015

modx minified error

It seems to happen on certain site that modx manager stop functioning properly.
when open in firebug, it shows modx minified returned error 400,
missing file.

when i appended &debug to the url, error starts showing out in firebug, and it indicates double appended path to the script.
the solution to this problem is to goto root/manager/mini/index.php

line #66 and add the bold code below:

if ($hasVirtualAssetsURL && !$hasVirtualManagerURL) {
    $min_serveOptions['minApp']['allowDirs'][] = MODX_ASSETS_PATH;
    $min_serveOptions['minApp']['virtualDirs'][MODX_ASSETS_URL] = MODX_ASSETS_PATH;

yes, ive already submitted a bug, and hopefully they have fixed it

Thursday, February 5, 2015

prestashop upload image: undefined error

my latest update on cpanel, were installing modsecurity with extra vendor from owasp.
it seems that 1 rule have caused prestashop to unable to upload image to product through the admin control panel. The rule effecting the upload is:

For example, these rules block GET requests with a body.
Basically it means it stop all post data if the url contains GET querystring...

hope it help you guys. You may disable this rule in the vendor - edit and off this line.