Add custom button to active admin form

孤街醉人 提交于 2019-12-24 14:08:18

问题


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

So 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 cant seem to grab the form object and pass through the params for post, title and comments

Thanks


回答1:


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


来源:https://stackoverflow.com/questions/33947555/add-custom-button-to-active-admin-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!