Rails Engine

Recently, I build some Rails engines. And I found it’s a good way to organize and share reusable code across a number of applications.

Rails Engine is not like Ruby gem. It’s more like a rails app, it has its own controllers, views and migrations. And basically it has two type of engine, full or mountable.

Capybara and Poltergeist with RSpec


capybara

I used to think cucumber for Rails is a little bit over kill for the developer. Because every time you have to write a lot of regular expression to work it out. But in the recently project, we use Capybara and poltergeist with RSpec to solve this problem. It even can test your SPA and integrate with CI very nicely.

Poltergeist is a driver for Capybara. It allows you to run your Capybara tests on a headless WebKit browser, provided by PhantomJS. So, what is headless? That means you don’t need to fire up your browser. What’s that mean? Fast!!

  • Poltergeist is a wrapper for PhantomJS, so make sure your test env have that. If not brew install phantomjs in Mac.
  • Travis CI and codeship has PhantomJS pre-installed.

Codeship


codeship logo

Nowaday, all the code should be tested before shipped. But we are all human being, we make mistakes. Sometime you are thinking just one line of code, not a big deal, just push it. Unfortunately, that line of code cause errors. So, we need something to automate test our codes after we pushed it to verify our code pass all the test case or not. That’s why CI introduced.

And for CI, in my option, there are two kinds right now, one is Jenkins with docker(more manual) and one is Codeship/travis-ci(more automated).

Angular on Rails - Basic Setup and Deploy


angular+rails

How to setup Angular with Rails

There are a lot of way you can integrate Angular with Rails, a common way is put Angular inside the Asset pipeline. It’s easy to integrate that way but the code base is quite mess at the later point. Recently, I found a way to use Yeomen generator and rails-api to work as front-end and back-end together.
Here’s some Pros and Cons for this way:

Pros:
  • Separate struct and codebase for front-end and back-end
  • Get rid of unused rails component like erb view template
  • No more need to fresh for front-end change
Cons:
  • have to deal with csrf token
  • need to setup the proxy
  • hard to deploy

Data Association with FactoryGirl

If you ever work with Rails and TDD, you may hear Factory girl: a great data mock gem to replace fixture. But sometime when your modal have some association with other modals, and that model have other associations, try to write a factory with callback (after build/create) become so hard. But thanks to thoughtbot, factory girl have data association build-in. You can read this post.

Static Images on Hexo

Hexo images hosting

After using couple month using Hexo, I found it’s fun and easy to use for logging technology/problem solutions. But the image system still not so great like other blog systems. But it’s 2014 now, there’s a lot of alternate ways to find a free image hosting service like Tumblr.

In my blog, I use tumblr as the image hosting system.