OAuth with OmniAuth and Twitter »

Created at: 07.11.2011 10:50, source: Ruby Rockers, tagged: Solutions oauth omniauth rails

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 :


more »

Respond to Custom Formats in Rails »

Created at: 24.10.2011 18:09, source: Ruby Rockers, tagged: Solutions Technology rails

We usually respond some of the known formats in Rails Application like HTML, XML, JavaScript, RSS and some custom.

Have you tried to use your own custom format for your Rails Application?

Yes you can use your custom format in Rails Application.

Here showing a simple Rails Application with responding custom formats.

Get a new app

rails new music_library 

Get a scaffold into App

rails generate scaffold mp3 title:string url:string description:text 

Ok so you are ready to serve some music on your app with some formats!

Now you have to register MIME types in the Rails Application.

For that open up Rails.root/config/initializers/mime_types.rb

Mime::Type.register 'audio/mpeg' , :mp3

Now you can serve .mp3 and content

For that your respond block should look like

def show
  @mp3 = Mp3.find(params[:id])
  respond_to do |format|
    format.mp3 { redirect_to @mp3.url }
  end
end

Now if you call this action with .mp3

http://localhost:3000/mp3s/1.mp3

You will redirect_to @mp3 url.

Happy adding custom formats!!


more »

Rails 3.1 and JRuby »

Created at: 10.10.2011 13:03, source: Ruby Rockers, tagged: Solutions Technology jruby rails

Hi Folks,

If you are doing any application in which you required JRuby as a platform. You can use Rails3.1 with that. activerecord-jdbc-adapter 1.2.0 is ok with that!

All the steps are same as for the normal Rails Application

You can find more details here http://blog.jruby.org/2011/09/ar-jdbc-1-2-0-released/

 

Cheers,
Arun


more »

Submit a patch for Rails on Github using “fork and edit button” »

Created at: 11.09.2011 10:49, source: Ruby Rockers, tagged: Solutions Technology contributions github rails

Hi Folks,

I have recently written about my Rails Contributions experience here.

I see that now days contribution is Rails is increased. People love to contribute in Open Source projects. And the way should be easy not painful.

I found that some people are struggling in submitting Pull Requests in Rails on Github. So i thought of writing the same to help them.

Some people are new to git and they don’t know much about git… or sometime patch is very small and they want to use Github’s “fork and edit this file” feature to submit a patch.

And some people who are good in Rails will do it in more easy manner. And easy to open multiple pull request at a time from the same branch.

I am writing some steps to use Github’s fork and edit feature to open pull request.

Open up your project on Github open up file where you want to change

Change your desired things into the file. You can only change one file in one commit

Propese your file changes! Here you can write about your changes. Give some references about issue. Can see the file changed. Can see the commits which you have made.

Change commit is the most important part. The reason is when people are doing changes in specific branch. Let’s take a example of Rails. If you are going to submit a patch against Rails 3.0.X version then you must have to choose 3-0-stable branch instead of master in Base branch.

After updating the commit range you can submit the Pull Request and also must see the File Changed.

Use this feature when you are fixing any typos, updating any docs. For submitting any code changes you should be running tests. :-)  

Feel free to ask me if you face any problem in doing these things. We want more contributions!

You can tweet me @arunagw or catch me on my email any time.

Cheers!


more »

Rails 3.0.10 and JRuby »

Created at: 05.08.2011 10:26, source: Ruby Rockers, tagged: Solutions jruby rails

Finally, The Rails is coming with template support with JRuby platform. We used to use “-m” option to generate new Rails Application for JRuby platform. Which is no more need now.

Just set your platform to JRuby and create a new Rails Application as you do normally and it will generate a Application which is ready to go. No more tweaks required..!!

This pull request which get merged into Rails 3-0-stable branch and it’s shipped with Rails 3.0.10.rc1 and will come with Rails 3.0.10.

This feature is also coming with Rails 3.1.

Showing here some of the example which will create Rails Application for JRuby platform. I have tested this on JRuby 1.6.3 version.

rvm jruby-1.6.3
# Will set your environment for JRuby 1.6.3 version.

Time to create rails app. This will generate a rails app for JRuby platform. Things like database.yml, Gemfile will generated specifically for JRuby platform.

rails new myapp

database.yml

# SQLite version 3.x
#   gem 'activerecord-jdbcsqlite3-adapter'

development:
  adapter: sqlite3
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3

production:
  adapter: sqlite3
  database: db/production.sqlite3

Gemfile

source 'http://rubygems.org'

gem 'rails', '3.0.10.rc1'

gem 'jruby-openssl'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'activerecord-jdbcsqlite3-adapter'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end

You can see in Gemfile the changes. It requires gem 'jruby-openssl' gem and gem 'activerecord-jdbcsqlite3-adapter' gem. Which is required for JRuby platform.

Same work to generate for mysql and postgres.

rails new myapp -d mysql

And that’s all.!!

Your Application is ready to run. Just do bundle install and all set. wOOtt..!!

Post comments and discuss things if you guys still facing any issue. You can also post issue on Rails Issues and ask me to look into that.

Some Useful links related to post:

  1. Activerecord-jdbc-adapter
  2. Jruby.org
Cheers,


more »