LoginSignup
0
0

More than 1 year has passed since last update.

Rails: How to make an action in ActiveAdmin.register_page

Last updated at Posted at 2019-04-16

I really struggled with ActiveAdmin's register_page (writing not associated with a model).

point

  • Add an action with page_action . page_action you do not write page_action , even routing will not be added! (But why, only the index action does not have to be defined from the beginning)

  • The part corresponding to index do ActiveAdmin.register is content do in register_profile! (It is hard to understand)

  • For example, if you write @text = 'ABCD' in index do , you can not use it in content do ! It is an ordinary variable called text.

  • Layout changes are written directly under controller do ! Do not write in def index or something.

  • def index and content do correspond. So, for example, what corresponds to def edit ? Maybe page_action: edit do. (Unsettled)

    ActiveAdmin.register_page "AuthorPage" do content do panel 'メニュー' do link_to '新規作成', admin_authorpage_new_path end table_for authors do column "名前", :name column "性別", :gender column ("name_changed"){ |author| author.name_changed } column ("編集"){ |author| link_to('編集する', admin_authorpage_edit_path(id: author.id)) } end end page_action :new, method: :get page_action :create, method: :post page_action :update, method: :post page_action :edit, method: :get do end controller do layout 'active_admin', only: [:edit, :new] def index @authors = Author.all end def new end def create Author.create(params.require(:author).permit(:name, :gender)) flash[:notice] = '作成しました。' redirect_to admin_authorpage_path end def update flash[:notice] = '編集しました。' author = Author.find(params[:author][:id]) author.update(params.require(:author).permit(:name, :gender)) redirect_to admin_authorpage_edit_path(id: params[:author][:id]) end def edit @author = Author.find(params[:id]) end end end

Original by

Rails: ActiveAdmin.register_page でのアクションの作り方とはまりどころ。

About

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0