Let's assume i have a member_action called approve, i'd loveto have a link beside the "View Delete Edit" actions
While I agree with the feature couldn't you do something like this:
index do
column :title
column :author
column() {|post| link_to 'Approve', :action => :approve }
end
I was able to add an edit link in one of my models using this method. YMMV.
+1 to be able to add to existing index actions. Clean and DRY.
IMO, default_actions or another helper method should automatically display links only if that action is available. So if actions are declared as
actions :index, :show, :edit, :update
the only link that would display would be "View" and "Edit"
Added the ability to :except specific default_actions buttons in my fork at https://github.com/struckaxiom/active_admin
Will submit a pull request if this is a generally acceptable modification.
To use, do this:
default_actions :except => [:delete, :edit]
Another addition, just added the :only option to default_actions. FYI, :except takes precedence over :only, for whatever reason that situation might come up.
https://github.com/struckaxiom/active_admin
Will pull request if this mod is generally acceptable.
@amoslanka This looks great! If you add some specs, I'd love to pull this in to the main line. If you have any questions about the Active Admin specs, feel free to ask. Cheers
Has the ability to be able to add to existing index actions been added?
@gregbell the @amoslanka patch working fine, if you can add this to current version it will be great. I think then we can close this issue. There is also another commit by knoopx which is for handling the active inherited resources at https://github.com/knoopx/active_admin/commit/eb42c9dc9b9c872f7f7d16c4efbc551c877743a1.
Bump, +1, this is simple and a common use case.
I'd like to see this implemented too.
This would be great!
+1
+1!
+1
Closing and adding to our list of feature requests. Will open when it's actually scheduled to be developed. And of course, we always accept pull requests :)
This was a great addition, but doesn't seem to solve the original problem of being able to add action items to the default_actions column. @fractur3d had a solution to add an action item, but this creates another column if also using default_actions. How do I use default_actions and add an action item to the same column?
@lukei8ii - additional DSL was added to do this in 0.6 release:
ActiveAdmin.register Post do
index do
column :name
actions defaults: true do |post|
link_to "Archive", archive_admin_post_path(post) if can?(:archive, post), class: "member_link"
end
end
end
Specifically it was #1834
Thanks @macfanatic and @Daxter
How i can add few custom actions to default actions?
actions do |tour| link_to "Clone", {:action => 'clone', :id => tour }, :method => :put link_to "Share", {:action => 'share', :id => tour }, :method => :put end
Now I can add correctly only one action.
You have to pass defaults: true
when calling actions
EDIT: misread what you were asking
This is the code in question:
def actions(options = {}, &block)
options = {
:name => "",
:defaults => true
}.merge(options)
column options[:name] do |resource|
text_node default_actions(resource) if options[:defaults]
text_node instance_exec(resource, &block) if block_given?
end
end
As you can see, the given block's return value is passed to text_node
. So one option would be to concatenate the links:
actions do |tour|
link_to("Clone", ...) +
link_to("Share", ...)
end
Thanks a lot!
@seanlinsley - this concatenation requirement is very non-intuitive, and delayed me for a fair bit.
This is my first time with arbre, or I'd send in a PR myself - basically, we need to switch from taking the return value of the block to the side effects generated by the functions inside - it that right?
How would you propose we do that? In Ruby there's no way to recognize the end-result of any given line of code in a block.
My ruby/rails experience is still pretty minimalistic, so hopefully it's helpful if I just describe how the current system defies my expectations.
In ERB or HAML, if I write code along the lines of
some_element do
link_to first_thing
link_to second_thing
end
I expect that both first_thing and second_thing will be linked. Here, this doesn't happen. Further, the example only provided one additional link, with no intuition on how to make multiple custom links work (something at least a few people need).
+
esactions({custom_actions: [link_to(first_thing), link_to(second_thing)...]})
`3. Provide an example that uses a partial, IE
actions do
render partial: "custom_user_links"
end
app/views/admin/custom_user_links.html.haml:
= link_to first_thing
= link_to second_thing
I am partial to solution #2, I think.
Grain of salt: I haven't dug into the source for this to see how it works.
The idiomatic way to do this would be to instance_eval the block given to actions
instead of relying on the return value of the block.
That may be easier said than done.
Normaly when we add default_action command... Then name for the column is empty... Is any way to rename the column....???
this needs some work!
We can show multiple action items in the following way:
actions defaults: false do |post|
item 'View', admin_post_path(post), class: 'member_link'
item 'Archive', archive_admin_post_path(post), class: 'member_link'
item 'Publish', publish_admin_post_path(post), class: 'member_link'
end
The above code will not display the default links of View
, Edit
, Delete
as we are passing defaults: false
to actions
method call. Also remember to add the class member_link
which adds space between links.
@danishsatkut Following your example, it work fine but I have a link to _delete_ with method set to delete
like below but how to add a dialog box to confirm the _delete action_ by the user as in a normal link_to
helper?
actions defaults: false do |user|
item 'View', optumadmin_user_path(user), class: 'member_link'
item 'Edit', edit_optumadmin_user_path(user), class: 'member_link'
item 'Delete', optumadmin_user_path(user), class: 'member_link', method: :delete
end
@AlexVentura
doesn't it just passes the args to the helper method?
item 'Delete', optumadmin_user_path(user), class: 'member_link', method: :delete, confirm: "Delete this item"
@krtschmr @danishsatkut Mmm it does not work for me!
Now it works adding data-
prefix:
item 'Delete', optumadmin_user_path(user), class: 'member_link', method: :delete, 'data-confirm': "Are you sure you want to delete this?"
Thanks!
@AlexVentura Try this:
item 'Delete', optumadmin_user_path(user), class: 'member_link', method: :delete, data: { confirm: "Delete this item" }
Most helpful comment
@lukei8ii - additional DSL was added to do this in 0.6 release: