1 Replies - 1406 Views - Last Post: 04 July 2016 - 07:30 AM Rate Topic: -----

#1 lllll  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-May 16

Disallow action item with condition in AdminUser

Posted 24 May 2016 - 02:22 AM

Hi, first question here, I hope to be specific and not stupid.
I'm new also in Rails and AdminUser and I would like to create a controller that show a menu item only if the current_user is of a certain type (in my case: Lektor).

I've written something like this:
  disallowed_actions = []
  disallowed_actions << :create if proc {current_admin_user.departments.to_a[0].name != "Lektor" }
  actions :all, :except => disallowed_actions



But it doesn't work, and I think it's because the current_admin_user I refer to in proc is not the same of the controller, but I also can't refer to the current_admin_user outside a method or a proc. Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: Disallow action item with condition in AdminUser

#2 sidk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-July 16

Re: Disallow action item with condition in AdminUser

Posted 04 July 2016 - 07:30 AM

Hey there, have you looked into a gem like CanCanCan for this?

The way you're suggesting is not something I'd consider idiomatic. If you don't want to use a gem, you could try something like this:

def create
  redirect_to <somewhere else> && return if lektor?
  ... # the rest of the create action
end

def lektor?
  current_admin_user.departments.to_a[0].name != "Lektor"
end


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1