Skip to content
Another Authlogic Vkontakte
Ruby JavaScript Shell
Find file
New pull request
Pull request Compare This branch is 29 commits ahead, 1 commit behind route:master.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



This is aavkontakte-rails3 - yet another authlogic vkontakte authorization gem. It provides vkontakte authorization to authlogic. This gem is tested with authlogic and authlogic-rpx on my project. Please report me about bugs. Vkontakte uses domain protection for url address of your site. But I noticed that: your-really-domain:3000 after closing popup window is works too. You must add your domain in /etc/hosts


gem install aavkontakte-rails3

  • Environment

In environment.rb:

config.gem 'aavkontakte-rails3'
  • User model

Add following line:

acts_as_authentic do |c|
  c.vkontakte_enabled = { :vk_app_id => "id", :vk_app_password => "password" }
  c.vkontakte_merge_enabled true     # mapping user data from vkontakte to new user account, true by default
  • UserSession model:

By default “vkontakte_merge_enabled” uses “map_vkontakte_data” method:

def map_vkontakte_data
  self.attempted_record.send("#{klass.login_field}=", @vkontakte_data[:user][:nickname]) if self.attempted_record.send(klass.login_field).blank?
  self.attempted_record.send("first_name=", @vkontakte_data[:user][:first_name]) if @vkontakte_data[:user][:first_name]
  self.attempted_record.send("last_name=", @vkontakte_data[:user][:last_name]) if @vkontakte_data[:user][:last_name]

If you set option to true, you need override it in user_session model.

  • Migrations

Create migration “script/generate migration add_vkontakte_id_to_user vk_id:string”:

class AddVkontakteIdToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :vk_id, :string
    # You must remove any database constraints for fields:
    # change_column :users, :crypted_password, :string, :null => true
    # change_column :users, :password_salt, :string, :null => true
    # change_column :users, :login, :string, :null => true

  def self.down
    remove_column :users, :vk_id
    # change_column :users, :crypted_password, :string, :null => false
    # change_column :users, :password_salt, :string, :null => false
    # change_column :users, :login, :string, :null => false
  • Layout

In the body section:

<%= init_vkontakte %>
  • Javascripts

After first start your application, it's copying vkontakte.js to your javascripts directory or if it doesn't exist.

  • Link

Put link somewhere, where you want:

<%= vkontakte_login_link_to "Login with vkontakte" %>

By default it uses action create of user_sessions controller. Parameters are identical link_to without block.

Contributing to aavkontakte-rails3

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2011 Dmitry Vorotilin. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.