我只希望用户myColumn LIKE convert(varchar(255), @myVariable) + '%'
+ devise
允许用户使用其instagram帐户登录我的应用。我尝试了一些教程,devcamp和railscast视频,但无法正常工作。是否有工作的分步指南,说明如何使用devise为instagram实现omniauth?
每次我想阅读文档时,我都会感到困惑,因为instagram将很多代码粘贴在一个代码块中,没有说明,该代码所属。而且他们从不使用普通的嵌入红宝石,而是使用haml和东西。
现在我明白了:
oauth
omniauth_callbacks_controller:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def instagram
end
end
routes.rb
devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}
initializers/devise.rb
在我的user.rb文件中,我放置了一些代码,其中包含我不太了解的会话内容,但也没有用。
答案 0 :(得分:0)
代码示例
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def instagram
session["devise.instagram_data"] = request.env["omniauth.auth"]
if user = User.from_omniauth(request.env["omniauth.auth"])
sign_in_and_redirect user
else
redirect_to new_user_registration_path
end
end
def failure
redirect_to root_path
end
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, omniauth_providers: [:instagram]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).take
end
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.instagram_data"]
user.uid = data["uid"]
user.provider = data["provider"]
user.password = Devise.friendly_token
end
end
end
end
完整示例在这里https://github.com/germanescobar/rails-devise-instagram/blob/master/app/models/user.rb