ActiveAdminでモデルの追加・更新を行った後、デフォルトの挙動では閲覧画面へ遷移します。これを一覧か編集画面へ遷移したい場合があると思います。
一覧へ遷移したい場合(モデルクラスをMyModelとする)
app/admin/my_model.rb
ActiveAdmin.register MyModel do
~ もろもろ記述 ~
controller do
def create
super do |success,failure|
success.html {
flash[:notice] = "Created."
redirect_to collection_path
}
end
end
def update
super do |success,failure|
success.html {
flash[:notice] = "Updated."
redirect_to collection_path
}
end
end
end
end
編集画面へ遷移したい場合
controller do
def create
super do |success,failure|
success.html {
flash[:notice] = "Created."
redirect_to action: 'edit', id: MyModel.last.id
}
end
end
def update
super do |success,failure|
success.html {
flash[:notice] = "Updated."
redirect_to action: 'edit'
}
end
end
end
flash[:notice]はなくてもいいですが、メッセージ表示したほうがユーザーに親切だと思います。
もちろん
flash[:notice] = I18n.t("created")
のようにローカライズもできます。