2015-11-26 8 views
5

私は次のこと「ユーザーを追加」=>「ユーザーの作成」、「ユーザーの編集」=>「ユーザーの更新」などのようなカスタマイズボタンと成功メッセージ

  1. アクション名をカスタマイズしたい
  2. 「ユーザー作成に成功」=>「顧客が正常に作成さ」のような
  3. 成功メッセージでは
  4. を、削除の作成と編集編集の横に表示ページ上のボタンを作成し、はい、それは可能である

答えて

4

を削除を追加します。

アクション=>、 "ユーザーの編集" => "更新 ユーザー" などf.actionsを持つことの代わりに

"ユーザーの作成"、あなたは

<%= f.actions do %> 
    <%= f.action :submit, as: :button, label: 'Create User' %> 
    <%= f.action :cancel, as: :link %> # change it to button if needed 
<% end %> 
持つことができ、 "ユーザーの追加" のような名前

ActiveAdminはformtastic、read more hereを使用します。

def create # or any other action 
    super do |format| # this is important - override the original implementation 
    flash[:notice] = 'Your custom message for successful user creation' 
    # you do understand, that if you have different routes you should change this, right? 
    redirect_to admin_users_path 
    end 
end 
:削除で

成功メッセージ、=>

def create # or any other action 
    super do |format| # this is important - override the original implementation 
    redirect_to(
     admin_users_path, 
     notice: 'Your custom message for successful user creation' 
    ) and return 
    end 
end 

ます。また、これを試みることができる "お客様正常に作成さ" "に成功 作成したユーザー" のような作成と編集

作成ボタンを追加編集と削除の横のページを表示

action_item only: :show do 
    link_to 'Create new user', new_admin_users_path 
    end 
+0

1と2を、あなたを助けることができるそれをカスタマイズするので、動作していません。.. .... 最初に、リンクとして表示をキャンセルします 2番目に、何も起こらない – Mukesh

+0

私は答えを編集しました。第1回 - 私が示唆したようにドキュメントを読み、[あなたにリンクを与えました](https://github.com/justinfrench/formtastic# - 物語)。 2それは動作するはずです、あなたは 'controller do end'ブロックの中でそれを定義しましたか? –

+0

ありがとうたくさんのおい...今すぐ全部働いて...... :) – Mukesh

3

私は2番目(上からrefrence)のための答えを追加することですが、上記の検証エラーで私が働いていない、より良い

controller do 

    def update 
     super do |format| 
     if [email protected]_object.errors.any? 
      redirect_to(
      admin_my_localities_path, 
      notice: 'custom message.' 
     ) and return 
     end 
     end 
    end 


    def destroy 
     super do |format| 
     if [email protected]_object.errors.any? 
      redirect_to(
      admin_my_localities_path, 
      notice: 'custom message.' 
     ) and return 
     else 
      redirect_to(
      admin_my_localities_path, 
      alert: 'custom error.' 
     ) and return 
     end 
     end 
    end 
end 
関連する問題