简体   繁体   中英

Add custom button to active admin form

Is it at all possible to add a custom button along side the submit and cancel button that is generated with f.actions in this case?

The documents state:

form do |f|
  f.semantic_errors # shows errors on :base
  f.inputs          # builds an input field for every attribute
  f.actions         # adds the 'Submit' and 'Cancel' buttons
link_to 'Preview', preview_my_admin_panel_posts_path(@post)
end

How could I add something here?

Update

I have got my custom button to show now with this:

inputs 'Submit' do
  f.actions do
    f.action :submit
    f.action :cancel
    f.action :reset
    li do
      link_to 'Preview', preview_my_admin_panel_posts_path()
    end
  end

Now I can't seem to grab the form object and pass through the params for post, title and comments .

Yea, it is possible.

define an action_item :

action_item only: %i(new edit) do
  link_to 'Preview', preview_my_admin_panel_posts_path(@post)
end

Ok, I think you could do the following:

form do |f|
  f.semantic_errors
  f.inputs
  f.actions do
    f.submit, as: :button, label: 'Optional custom label'
    f.cancel, as: :link # I think could converted to button as submit
    link_to 'Preview', preview_my_admin_panel_posts_path(@post)
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM