A
A
Artyom2012-03-30 22:26:43
Ruby on Rails
Artyom, 2012-03-30 22:26:43

Active Admin. How to assign the current user of a post when it is created?

I use Cancan to filter access:

scope_to :current_manager, :association_method => :blog_posts
  controller do
    private
    def current_manager
      unless can? :manage, :all
        current_user
      end
    end
  end


A side effect of this code is that although the administrator can see all the records, when he adds a new record, the user_id field remains empty. How can I assign the current user to a new record, regardless of access rights?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sdevalex, 2012-03-30
@Dracontis

bafore_save in model...

S
solenko, 2012-06-19
@solenko

It seems to me, all the same, it is better to override create
with something like

controller do
  create
    create! do |success, failure|
      if success
         # set current manager here

      end
    end
  end
end

It is not good for the model to know from the current user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question