Comments (35)
@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
from activeadmin.
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.
from activeadmin.
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.
from activeadmin.
@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
from activeadmin.
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
from activeadmin.
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"
from activeadmin.
@AlexVentura Try this:
item 'Delete', optumadmin_user_path(user), class: 'member_link', method: :delete, data: { confirm: "Delete this item" }
from activeadmin.
this needs some work!
from activeadmin.
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!
from activeadmin.
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.
from activeadmin.
+1 to be able to add to existing index actions. Clean and DRY.
from activeadmin.
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"
from activeadmin.
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]
from activeadmin.
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.
from activeadmin.
@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
from activeadmin.
Has the ability to be able to add to existing index actions been added?
from activeadmin.
@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.
from activeadmin.
Bump, +1, this is simple and a common use case.
from activeadmin.
I'd like to see this implemented too.
from activeadmin.
This would be great!
from activeadmin.
+1
from activeadmin.
+1!
from activeadmin.
+1
from activeadmin.
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 :)
from activeadmin.
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?
from activeadmin.
Specifically it was #1834
from activeadmin.
Thanks @macfanatic and @daxter
from activeadmin.
You have to pass defaults: true
when calling actions
EDIT: misread what you were asking
from activeadmin.
Thanks a lot!
from activeadmin.
@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?
from activeadmin.
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.
from activeadmin.
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).
Proposed solutions:
- Add an example with multiple links that uses
+
es - Instead of a block, take arguments to the actions function, IE
actions({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.
from activeadmin.
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.
from activeadmin.
Normaly when we add default_action command... Then name for the column is empty... Is any way to rename the column....???
from activeadmin.
@krtschmr @danishsatkut Mmm it does not work for me!
from activeadmin.
Related Issues (20)
- undefined method `to_ary` for Enumerator (Rails 7.1.1 & Activeadmin 3.1.0) HOT 4
- index columns / show rows
- `contains` filter no longer working HOT 1
- Update action does not call `authorize_resource!` after assigning attributes HOT 10
- uninitialized constant InheritedResources::Base (NameError) HOT 1
- Filtering on associations does not use the foreign_key when defined HOT 3
- Uninitialized constant `Devise::SessionsController` when extending controller HOT 1
- Rails 7.1.2 compatibility HOT 1
- InvalidAuthenticityToken Can't verify CSRF with rails 7.1.2.
- v4 beta 3: Kaminari translation override may affect the host application HOT 2
- v4 beta 3: External CDNs do not play well with CSP and may be a problem for intranet apps HOT 2
- Defining Actions in Index as a Table (4.0.0.beta3) HOT 3
- after_save called even if validation fails HOT 5
- 4.0.0.beta4 nesting in menus HOT 6
- Indentation broken for nested lists HOT 1
- No access to routes helpers from ActiveAdmin views [v4.0.0.beta5] HOT 8
- Fix DateRange Filter last day confusion regression
- Importmap is optional, but raise error if it is not installed. HOT 1
- v4: add accessible names for buttons HOT 5
- v4: on large screens, the sidebar navigation has `aria-hidden="true"` even if it is not hidden
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activeadmin.