2015-11-26 31 views
5

我想自定義下面的事情自定義按鈕,併成功消息在主動管理的Rails

  1. 操作名稱,比如「添加用戶」 =>「創建用戶」,「編輯用戶」 =>「更新用戶」等
  2. 成功消息在刪除,創建和編輯,如「用戶成功創建」 =>
  3. 添加創建按鈕在顯示頁面編輯旁邊,刪除

回答

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 
    redirect_to(
     admin_users_path, 
     notice: 'Your custom message for successful user creation' 
    ) and return 
    end 
end 

你也可以試試這個:

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 

在顯示頁面上添加創建按鈕旁邊的編輯和刪除

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

1和2不工作.. ... 第一,取消顯示爲鏈接 第二,沒有發生 – Mukesh

+0

我編輯了答案,第1 - 閱讀文檔,因爲我建議和[給你鏈接](https://github.com/justinfrench/formtastic#的 - 故事)。 2它應該工作,你是否在'controller do end'塊中定義它? –

+0

非常感謝Dude ...現在所有工作...... :) – Mukesh

3

我加入了第二(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