我設置的gravatar並得到了它的工作我'users/*user id goes here*'.
但每當我嘗試時,它給我的錯誤使用它在dashboard/index
這是的Gravatar - 未定義的方法「郵件」的零:NilClass
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的!
BOOM!這就是CURRENT_user,這是我需要感謝的一部分。但我也需要它,以便用戶可以鍵入導航到其他用戶儀表板並查看他的gravatar,有什麼想法? – coreypizzle 2013-03-18 19:06:46
你如何瀏覽..你是否提供任何鏈接給用戶? – codeit 2013-03-18 19:09:16
是的,我提供了一個鏈接。 – coreypizzle 2013-03-18 19:09:40