Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active September 3, 2015 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/7bd7fa13902656e4b158 to your computer and use it in GitHub Desktop.
Save YumaInaura/7bd7fa13902656e4b158 to your computer and use it in GitHub Desktop.
Rails: ActiveAdmin.register_page でのアクションの作り方とはまりどころ。 ref: http://qiita.com/Yinaura/items/3572d34e1c00f9f5533e
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment