3

현재보고있는 개체의 인스턴스를 어떻게 참조 할 수 있습니까?ActiveAdmin - 현재 객체를 참조하는 방법?

ActiveAdmin.register Example do 

    sidebar "test" do 
    @name = example.name 
    end 

end 

를 수행하면

ActiveAdmin.register Example do 

    member_action :some_stuff, :method => :put do 
    @name = example.name 
    end 

end 

작동하지 않습니다 WORKS

다음은 어떻게 member_action의 객체를 참조 할 수 있습니까?

아니면 다른 인스턴스를 만들어야합니까?

답변

4

대부분의 활성 관리 설명서가 오래되었거나 완전히 존재하지 않습니다. 사용자는 소스 코드를 읽어야하며, 사용법에 대한 핵심적인 내용을 원한다면 누군가가 기능에 대해 의견을 말하기를 바랍니다. - Post.find(params[:id])

# Member Actions give you the functionality of defining both the 
# action and the route directly from your ActiveAdmin registration 
# block. 
# 
# For example: 
# 
# ActiveAdmin.register Post do 
#  member_action :comments do 
#  @post = Post.find(params[:id] 
#  @comments = @post.comments 
#  end 
# end 
# 
# Will create a new controller action comments and will hook it up to 
# the named route (comments_admin_post_path) /admin/posts/:id/comments 
# 
# You can treat everything within the block as a standard Rails controller 
# action. 
# 

이 그들이 당신이 사용자 지정 작업에 자신의 개체 조회를 수행 할 것으로 예상 것처럼 보이게 다음과 같이

member_action function documentation입니다.

1

'리소스'개체를 사용할 수 있습니다.

ActiveAdmin.register Example do 

    member_action :some_stuff, :method => :put do 
    @name = resource.name 
    end 

end 
관련 문제