Skip to content

Instantly share code, notes, and snippets.

@mchung
Created March 16, 2011 02:13
Show Gist options
  • Save mchung/871894 to your computer and use it in GitHub Desktop.
Save mchung/871894 to your computer and use it in GitHub Desktop.
Get started with OAuth and Rails in 5 minutes

Get started with OAuth and Rails in 5 minutes

Assumptions

Before you get started, I'm assuming you've got the following setup on your machine:

  • Rails-3
  • RVM

Create a new Rails-3 application

$ rails new OAuthExample
$ echo "rvm --create 1.9.2-p180@oauthexample" > OAuthExample/.rvmrc
$ cd OAuthExample
$ gem update
$ bundle install
$ ./script/rails s

Add omnisocial to your Gemfile

gem 'omnisocial', '0.1.2'

Install omnisocial

$ bundle update
$ rails g omnisocial

Add your APP_KEY and APP_SECRET to config/initializers/omnisocial.rb

config.twitter 'sekret_Key', 'sekret_Secret'

Get your database updated

rake db:migrate

Setup a default controller

./script/rails g controller welcome index

Update the index.html.erb partial

<h1>Hello Phoenix Rubyists</h1>
<p>Find me in app/views/welcome/index.html.erb</p>


<%= link_to "Login", login_path %>

<% if current_user? %>
  <p>
    Hello, <strong><%= current_user.login %></strong>
  </p>
  <p>
    <%= link_to "Logout", logout_path %>
  </p>
<% end %>

Delete the public/index.html

rm public/index.html

Start the application and login!

$ ./script/rails s

Click on login

Want to learn more?

Me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment