"Create use...">

Customize Button and Success message in Active Admin Rails

I want to configure the following things

  • Actions Type name "Add user" => "Create user", "Change user" => "Update user", etc.
  • Successful completion message: "Delete", "Create and edit", for example, "user created successfully" => "client created successfully"
  • Add the Create button on the View page next to editing and deleting
+5
source share
2 answers

Yes it is possible.

Actions Type name "Add user" => "Create user", "Change user" => "Update user", etc.

Instead of f.actions , you might have

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

ActiveAdmin uses formtastic, read here .

Successful start message "Delete", "Create" and "Change", for example, "user created successfully" => "client created successfully

 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 

You can also try the following:

 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 

Add the Create button on the Show page next to editing and deleting

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

I am adding an answer for the second (refrence from above), but when checking for errors the above does not work, so I am setting it up, which may help you better

  controller do def update super do |format| if !@your _object.errors.any? redirect_to( admin_my_localities_path, notice: 'custom message.' ) and return end end end def destroy super do |format| if !@your _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 
+3
source

Source: https://habr.com/ru/post/1236922/


All Articles