ruby on rails - Contextual output using decorators -


i want give contextual output, , have thought decorator place put logic. however, can't access current_user method in decorator.

right now, i'm doing in view:

<% if current_user == @user %> <% else "#{@user.username}'s" end %> profile 

and seems bit messy. want in draper. first step towards goal:

class userdecorator < applicationdecorator   delegate_all    include sessionshelper            def is_owner?     current_user === model   end  end 

my sessions helper:

module sessionshelper      def current_user=(user)         @current_user = user     end      def current_user         remember_token = user.hash(cookies[:remember_token])         @current_user ||= user.find_by(remember_token: remember_token)     end end 

however, results in:

undefined local variable or method `cookies' #<userdecorator:0x000000054ad2d8>  app/helpers/sessions_helper.rb:9:in `current_user' app/decorators/user_decorator.rb:9:in `is_owner?' app/views/users/show.html.erb:37:in `_app_views_users_show_html_erb___2600317495065048162_44417960' 

i include module contains cookies method (what part of rails way?), can't thinking i'm doing wrong if need include of stuff?

i want in draper:

<% if current_user == @user || current_user.is_admin? %>     <!-- buttons leading private functionality --> <% end %> 

but don't know how output complex multi-lined html collection of buttons. should create partial of secret section of html , render partial decorator?

if you're using draper gem , want use helper methods inside decorator, should call them h.. in case h.current_user


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -