Arun Agrawal’s Blog

Ruby on Rails Developer

Interview on RubyIndia Podcast

Recently I had an interview on RubyIndia Podcast and we talked about my early experiences with Ruby, starting my contributions to Open Source Projects and currently Ruby on Rails, work and culture at thoughtbot.

If you are interested in listening to me make sure to check this out.

http://podcast.rubyindia.org/rubyindia/10

This event was recorded on Hangout on Air and raw version is available here.

https://www.youtube.com/watch?v=Hgm1SlEdKG8

I would like to give credits for few people about this

Rails4 App on Heroku

Updated : Heroku has updated to use ruby2.0. by default.

If you are deploying a new rails4 app on heroku that might fail. And you will get following error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.3.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
       Fetching gem metadata from https://rubygems.org/..........
       Fetching gem metadata from https://rubygems.org/..
       Installing rake (10.0.4)
       Installing i18n (0.6.4)
       Installing minitest (4.7.4)
       Installing multi_json (1.7.7)
       Installing atomic (1.1.9)
       Installing thread_safe (0.1.0)
       Installing tzinfo (0.3.37)
       Installing activesupport (4.0.0.rc1)
       Gem::InstallError: activesupport requires Ruby version >= 1.9.3.
       An error occurred while installing activesupport (4.0.0.rc1), and Bundler cannot
       continue.
       Make sure that `gem install activesupport -v '4.0.0.rc1'` succeeds before
       bundling.
 !
 !     Failed to install gems via Bundler.
 !

 !     Push rejected, failed to compile Ruby/Rails app

In short, it says

1
Gem::InstallError: activesupport requires Ruby version >= 1.9.3.

Problem is that heroku uses ruby 1.9.2 by default

To check this run this command from your app

1
heroku run ruby -v

The output will be

1
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

Solution is simple, we need to attach ruby-version with app to tell heroku to use ruby 1.9.3 or higher because rails4 works with ruby-1.9.3 or higher.

Now add this following in your app Gemfile

1
ruby '1.9.3'

This will force heroku to use your desired ruby. Here we are using 1.9.3

This solution will work for your rails4 versions(4.0.0.beta1, 4.0.0.rc1, 4.0.0.rc2) apps.

Switched to Heroku and Octopress

I started posting blogs using self hosted Wordpress solution. After few years I realize that I should use Ruby/Rack framework. And drop this old way of doing blog post.

I tried moving away from Wordpress few times and one day got success. Finally I converted my all blog posts into markdown format.

Now it’s very easy to choose a Ruby/Rack based framework as posts are already in markdown.

After that I bought a theme from bootstrap and applied that, but I was still using my hosted solution with middleman generated site.

I survived with this for a long time. Problem was for every blog post I have to deploy site using git pull every time by logging into server.

At last I found octopress and a Heroku combination.

And here is my blog! Using Octopress and Heroku and I love it. Simple and easy!

OAuth With OmniAuth and Twitter

Hi Folks, If you want to have OAuth in your Rails Application with twitter. OmniAuth is the best gem to use. OmniAuth provides list of  Strategies to use many OAuth for your application. Here is the List of Strategies. Showing here a Twitter Strategy for OmniAuth. Twitter uses the OAuth 1.0a flow, you can read about it here: https://dev.twitter.com/docs/auth/oauth For using Twitter OAuth you have to register a Application on Twitter (https://dev.twitter.com/apps/new) Once you done with the registration obtain the Consumer Key and Consumer Secret from the Twitter Application. Be sure to put the callback URL in the application. Callback URL is the URL where user will land after successful authentication. Showing an image here how to register an Application with Twitter.   Here showing some of the steps : Generate a new Rails Application:
rails new TwitterAuth
Update your gemfile add omniauth-twitter gem into that
gem "omniauth-twitter"
Create a config/initializers/omniauth.rb file. Paste your key instead of XXXX, and secret instead of YYYY
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, 'XXXX', 'YYYY'
end
All Done! Just start the server
bundle exec rails server
And hit the URL
http://localhost:3000/auth/twitter
And you should be landing on the Twitter Authorize page! After success your app will redirect to your given callback URL with information and token! At OmniAuth.org you can try out different -2 Strategies.   Useful links :