Pugetworks
Seattle Software Developers

blog-archive

Pugetworks Blog Archive!

Adding users to Ruby on Rails


Wow...


That was easy. Devise is a great little gem that lets you add user accounts to your rails application. It should be one of the first things you setup. It has addons to hook up facebook logins (via the Facebook Graph API) and OAth. I didn't try any of this yet, I just wanted the plain vanilla setup. Before you go through this you might need to update the versions (go here http://rubygems.org/, type in devise) but, as of today this is all up to date.

1. Add this to your "Gemfile"

gem 'devise', '1.1.7'


2. Run this

bundle install


3. Then this

rails g devise:install


4. Next this

rails generate devise User


5. And don't forget a little of this

rake db:migrate


6. Add this to development.rb within the class

config.action_mailer.default_url_options = { :host => 'localhost:3000' }


6. Add this to application.html.erb

<%= notice %>

<%= alert %> <%= yield %>

<% if user_signed_in? %> Signed in as <%= current_user.email %>. Not you?<%= link_to "Sign out", destroy_user_session_path %> <% else %> <%= link_to "Sign up", new_user_registration_path %>or <%= link_to "sign in", new_user_session_path %> <% end %>


7. Turn on the server

rails server


8. Check it out

localhost:3000


Good work Devise guys. Coming from a background with Java Spring Security that was amazingly simple.

Rails, RubyMatt Paulin