我正在为我的博客尝试 Twitter 身份验证。我已经在我的应用程序中实现了设计。所以我在关注http://railscasts.com/episodes/235-devise-and-omniauth-revised
视频。当我完成此视频中提到的所有步骤并尝试访问我的应用程序时,我遇到了cannot load such file -- omniauth
错误。错误消息的详细信息如下。
Extracted source (around line #12):
9: <div id="tabs">
10: <ul id="tabs">
11: <li><div style="color:#82b548;font-size: 0.9em;"> <%= time_tag(article.created_at.in_time_zone("Asia/Calcutta")) %> </div></li>
12: <li> <div style="color:#4895d1; font-size: 0.9em;"> <%= article.user.username if article.user %></div></li>
13: <% if !article.nil? %>
14: <li><div style="color:#CCD600; font-size: 0.9em;"> <%= article.comments.size %> comments </div></li>
15: <li><div style="color:#CCD600; font-size: 0.9em;"> <%= link_to article.tags.collect(&:name).join(" ") %> </div></li>
Rails.root: f:/kuta/billi
Application Trace | Framework Trace | Full Trace
app/models/user.rb:15:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/views/articles/index.html.erb:12:in `block in _app_views_articles_index_html_erb__265352894_31994844'
app/views/articles/index.html.erb:6:in `each'
app/views/articles/index.html.erb:6:in `_app_views_articles_index_html_erb__265352894_31994844'
模型/用户.rb
class User < ActiveRecord::Base
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
attr_accessible :title, :body
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email, :on => :create
validates_presence_of :username, :on => :create
validates_uniqueness_of :email
validates_uniqueness_of :username
has_many :articles, :order => "created_at DESC"
has_many :comments
# Include default devise modules. Others available are:
# :token_authenticatable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end
def self.new_with_session(params, session)
if session["devise.user_attritubes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
end
我认为错误在于我的代码的 12 行,它与用户有关。但确切地说,我不知道我错过了什么。如果您需要粘贴更多代码,请告诉我。谢谢