问题
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