Last active
September 3, 2015 10:46
-
-
Save YumaInaura/7bd7fa13902656e4b158 to your computer and use it in GitHub Desktop.
Rails: ActiveAdmin.register_page でのアクションの作り方とはまりどころ。 ref: http://qiita.com/Yinaura/items/3572d34e1c00f9f5533e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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