Thursday, April 23, 2015

How to Link a Git Folder with an Existing Heroku App


  1. Follow this guide to get Heroku setup on your command line tool of choice.
  2. heroku git:remote -a project_name

where project name is the name of your Heroku app (if your app's URL is stellablog.herokuapp.com, project_name would be stellablog) and you're done! Your local Git folder will be linked with your Heroku app, and you can deploy your latest code to it.

Monday, April 20, 2015

How to Push a Local Branch to a Separate Remote Branch

This is my first post about Git! I'll be talking about how to push the contents of a local branch to a remote branch that is different from what it currently points to. The base syntax is

git push remote local_branch:remote_branch

An example of when to use this is in combination with Heroku. You might want to push your local branch to Heroku's master branch:

git push heroku foo_branch:master

That is also how you make Heroku run a non-master git branch.

Maybe you want to push the contents of your current branch to another branch on git:

git push origin foo_branch:bar_branch

Thursday, April 16, 2015

How to use respond_to? with private methods

respond_to? is an awesome method for testing if an object has a given method. By default, it will return false for methods that are private. If you want to test if an object has a method regardless of its private status, you can just pass true after the method name:

respond_to?(:foo, true)

Monday, April 13, 2015

How to Load Dependencies in a Rails Engine

In a Rails project, generally all you have to do is add a gem to your Gemfile and the dependencies will automagically get taken care of. Unfortunately, for Rails Engines this is not the case. You will have to take the additional step of requiring the gem's library file.

# engine.gemspec s.add_dependency 'jquery-rails' s.add_dependency 'your-foo-gem' # lib/your_engine/engine.rb
require 'jquery-rails'
require 'your-foo-gem'


This is related to the problem of needing to require modules from gems to get them to load properly.

Thursday, April 9, 2015

How to specify a local gem in your Gemfile

If you're developing a gem and you want to test it out locally in another project, this is easily accomplished by specifying the path to the local gem in your Gemfile:

gem 'bears', path: '/path/to/bears/gem'

and boom, it's there. One bundle install later and you'll be good to go.

Monday, April 6, 2015

Removing extra whitespace from Haml

Most of the time, Haml is pretty awesome. One of the cases where it's not so awesome is around multiline mixed Ruby/HTML. For example, when trying to create a timer on the screen:

Because of reasons, Haml decides to add extra whitespace around each of the span tags. Sometimes this is desirable, but sometimes you want to remove the whitespace/extra space around Haml tags. As usual, there is a quick fix, in this case the '>' character:

Thursday, April 2, 2015

Capybara::Poltergeist::TimeoutError

Timed out waiting for response to {"name":"visit","args":["http://127.0.0.1:54242/"]}. 
It's possible that this happened because something
took a very long time (for example a page load was slow). 
If so, setting the Poltergeist :timeout
 option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Poltergeist - please report it to the issue tracker. (Capybara::Poltergeist::TimeoutError)
While working with Capybara feature specs and Poltergeist, you may have encountered this error before. You also probably tried bumping up the timeout value to no avail. I found a surprisingly easy fix for this issue - update your Poltergeist gem and update PhantomJS to version 2.0! After I did these two things, most of these errors went away.

If you are still having issues after that, read through this issue and see if a solution there helps.