已更新,会话数据CURRENT_USER零值
pastebin.com/nGGriw7e
我有一个竞赛控制器,其从应用控制器继承
我们使用守门人的宝石。
在应用控制器我们的CURRENT_USER定义,并设置为一个辅助方法
helper_method :current_user, :require_user, :require_no_user
def current_user
@current_user ||= current_user_session && User.find(current_user_session.resource_owner_id)
end
private
def current_user_session
@current_user_session ||= Doorkeeper::AccessToken.find_by_token session[:access_token]
end
我打网址/contests
这伤害contest#edit controller
def edit
@contest = Contest.find params[:id]
end
这edit.html.erb我里面在呈现编辑素材之前部分地渲染侧导航
<div class="col-md-2">
<ul class="left-nav">
<% if @current_user.admin? or (@current_user.brand_admin? and @current_user == @contest.user) %>
<% if @current_user.admin? %><li><%= link_to 'New Contest', new_contest_path %></li><% end %>
<% if @contest and [email protected]_record? %>
<li><%= link_to 'Edit Contest', edit_contest_path(@contest) %></li>
<li><%= link_to 'All Contests', contests_path %></li>
<% end %>
<% end %>
</ul>
</div
这里是服务器日志
Started GET "/contests/5/edit" for 127.0.0.1 at 2014-09-18 17:29:14 -0400
Processing by ContestsController#edit as HTML
Parameters: {"id"=>"5"}
Contest Load (0.4ms) SELECT `contests`.* FROM `contests` WHERE `contests`.`id` = 5 LIMIT 1
Rendered contests/_side_nav.html.erb (2.0ms)
Rendered contests/edit.html.erb within layouts/application (2.8ms)
Completed 500 Internal Server Error in 7ms
NoMethodError - undefined method `admin?' for nil:NilClass:
更好的错误
我收到@current_user是零
>> @current_user
=> nil
这没有任何意义。我登录,甚至设立了这个特殊的用户具有role = "admin" inside rails c.
你有什么会议?你可以在控制器操作中记录它吗? (把session.inspect) – konole 2014-09-18 21:36:09
这里是我的,我不明白。 http://pastebin.com/nGGriw7e – Jngai1297 2014-09-18 21:48:48