尝试将 rolify 方法应用于我的用户,我收到以下错误:
undefined method `has_role?' for nil:NilClass
我不明白为什么,因为 current_user 应该是每个视图都可以访问的全局方法,对吧?怎么可能是零?
谢谢!
控制器
def show
@photo = Photo.friendly.find(params[:id])
impressionist(@photo)
@photos = Photo.latest_photos
@user = @photo.user
@pin = Pin.new
@pin.photo_id = @photo.id
@category = Category.all
@commentable = @photo
@comments = @commentable.comments
@comment = Comment.new
@sponsors = @photo.sponsors
@zone = Zone.all
respond_to do |format|
format.html #show.html.erb
format.json {render json: @photo}
end
end
我的观点
<% if current_user.has_role? :admin %>
<%= link_to "Eliminar", user_photo_pin_path(user_id: @user.id, photo_id: @photo.id, id: pin.id) , method: :delete, data: { confirm: 'Quieres borrar esto?'}, class: "delete right" %>
<%= link_to 'Editar', edit_user_photo_pin_path(user_id: @user.id, photo_id: @photo.id, id: pin.id), :class=> "link", class: "edit quarter_margin_right right" %>
<% end %>
<% end %>