How to run whenever with rvm integration

Simply overwrite the job_type to include the rvm version you want

job_type :rake, "source /etc/profile.d/rvm.sh && rvm use ruby-2.0.0-p247 && cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"

every 1.day, :at => '8:00 am' do
  rake "users:activities"
end

Rails Complex Order Query

Today gonna talk about Rails Complex Query for ordering. Here’s a simple query order by status

@events = @events.order("status DESC")

But what happen if you want to make the query to order the status in a specific sequence. Here’s the example:

@events = @events.order("
CASE
WHEN events.status = 'NEW' THEN 0
WHEN events.status = 'OPEN' THEN 1
WHEN events.status = 'UPDATED' THEN 2
WHEN events.status = 'WAITING' THEN 3
WHEN events.status = 'ABANDONED' THEN 4
ELSE 5
END")

Happy Hacking, Enjoy! 🙂

Simple Rails AJAX CRUD

Recently just got some time to do my own stuff. So I just extract a simple rails Ajax crud js file from the project I done before and published it. More details on Simple Rails AJAX CRUD. Which only has 52 lines. Hope u like it~

Was thinking to write a todo to rewrite it into using PJAX. But realised that push state wouldn’t be too useful for CRUD actions. As storing navigation history after deleting a record wouldn’t be fun.

Redmine and Integrity CI on Heroku

Following are some experience that I wanna share on how to have free hosting of Redmine for project management and Integrity for CI on Heroku.

Warn: don’t do it unless u are bored like me.

Redmine

Problems of running Redmine on Heroku:

  • Integrate Redmine with S3 for files

Solution: Redmine_S3 plugin

  • Integrate Github Repo

Solution:

    1. At the root of the Redmine repository, cd repositories/xxxx.git
    2. git fetch
    3. git reset –soft FETCH_HEAD
    4. cd ../..
    5. git add -A
    6. git ci -m ‘update repository’
    7. git push heroku master
    8. heroku run:console Repository.fetch_changesets

Integrity CI

Problems of running Integrity on Heroku:

  • Bundler not found.

Because Heroku’s Bundler is installed in the system path. But after bundle install, the GEM_HOME is set to /.bundle which doesn’t contain Bundler. And need the hack of putting the bundler into .bundle/ manually.

  • Gem not found

As Rake tasks are running at the tmp folder(e.g. tmp/1) And looking for Gems at the GEM_HOME /.bundle. Therefore, I have to install Test environment gems on Integrity.

Heroku Buildpack