我已经设置了 gravatar 并让它为我工作'users/*user id goes here*'.
但是每当我尝试使用它dashboard/index
时,它就会给我错误
Undefined method 'email' for nil:NilClass
我的仪表板控制器是:
class DashboardController < ApplicationController
def index
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end
end
仪表板视图:
<div class="dash-well">
<div class="gravatar-dashboard">
<%= image_tag avatar_url(@user), :class => 'gravatar' %>
<h1 class="nuvo wtxt"><%= current_user.username.capitalize %></h1>
</div>
</div>
我的应用助手:
module ApplicationHelper
def avatar_url(user)
default_url = "#{root_url}images/guest.png"
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=200{CGI.escape(default_url)}"
end
def avatar_url_small(user)
default_url = "#{root_url}images/guest.png"
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=40{CGI.escape(default_url)}"
end
end
我的用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :user_id, :id, :website, :bio, :skype, :dob, :age
has_many :posts
# attr_accessible :title, :body
end
我的仪表板模型:
class Dashboard < ActiveRecord::Base
attr_accessible :status, :author, :email, :username, :id, :user_id, :user, :website, :bio, :skype, :dob, :age
belongs_to :user
end
抱歉,我对 Ruby-On-Rails 还很陌生!