セッションデータで更新
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
ヒットするURL/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 !@contest.new_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 を nil にしています
>> @current_user
=> nil
これは意味がありません。私はログインしており、この特定のユーザーがrole = "admin" inside rails c.