2015-11-26 19 views
5

Tôi muốn tùy chỉnh điềuCustomize Nút Và thành công tin nhắn trong Active quản Rails

  1. Actions Đặt tên như "Add User" => "Tạo tài khoản", "Chỉnh sửa tài khoản" => "Cập nhật tài khoản" vv
  2. sau
  3. thành công tin nhắn trên delete, tạo và chỉnh sửa như "người sử dụng tạo thành công" => "khách hàng tạo thành công"
  4. Thêm Một Tạo nút On hiện trang bên cạnh chỉnh sửa và xóa

Trả lời

4

Vâng, đó là có thể.

Actions Đặt tên như "Add User" => "Tạo tài khoản", "Chỉnh sửa tài khoản" => "Cập nhật tài" vv

Thay vì phải f.actions, bạn có thể có

<%= f.actions do %> 
    <%= f.action :submit, as: :button, label: 'Create User' %> 
    <%= f.action :cancel, as: :link %> # change it to button if needed 
<% end %> 

ActiveAdmin sử dụng formtastic, read more here.

Success nhắn On Xóa, Tạo và chỉnh sửa như "sử dụng thành công tạo" => "khách hàng tạo thành công"

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 

Bạn cũng có thể thử điều này:

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 

Thêm nút tạo trên trang hiển thị bên cạnh chỉnh sửa và xóa

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

1 và 2 không làm việc .. .... Đầu tiên, Hủy hiển thị dưới dạng liên kết Thứ hai, Không có gì xảy ra – Mukesh

+0

Tôi đã chỉnh sửa câu trả lời, đọc tài liệu 1 như tôi đã đề xuất và [cho bạn liên kết] (https://github.com/justinfrench/formtastiC# the-story). 2 nó sẽ làm việc, bạn đã xác định nó bên trong 'điều khiển làm kết thúc' khối? –

+0

Cảm ơn rất nhiều Dude ... Bây giờ tất cả làm việc ...... :) – Mukesh

3

tôi thêm câu trả lời cho thứ hai (refrence từ trên cao), Nhưng Mở lỗi xác nhận ở trên không hoạt động vì vậy tôi tùy chỉnh nó có thể giúp bạn tốt hơn

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 
Các vấn đề liên quan