GithubHelp home page GithubHelp logo

Comments (35)

macfanatic avatar macfanatic commented on May 22, 2024 49

@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.

danishsatkut avatar danishsatkut commented on May 22, 2024 27

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.

bartezic avatar bartezic commented on May 22, 2024 9

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.

alexventuraio avatar alexventuraio commented on May 22, 2024 8

@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.

seanlinsley avatar seanlinsley commented on May 22, 2024 2

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.

krtschmr avatar krtschmr commented on May 22, 2024 2

@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"

from activeadmin.

danishsatkut avatar danishsatkut commented on May 22, 2024 2

@AlexVentura Try this:

item 'Delete', optumadmin_user_path(user), class: 'member_link', method: :delete, data: { confirm: "Delete this item" }

from activeadmin.

krtschmr avatar krtschmr commented on May 22, 2024 1

this needs some work!

from activeadmin.

alexventuraio avatar alexventuraio commented on May 22, 2024 1

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.

torrick avatar torrick commented on May 22, 2024

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.

DougPuchalski avatar DougPuchalski commented on May 22, 2024

+1 to be able to add to existing index actions. Clean and DRY.

from activeadmin.

amoslanka avatar amoslanka commented on May 22, 2024

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.

amoslanka avatar amoslanka commented on May 22, 2024

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.

amoslanka avatar amoslanka commented on May 22, 2024

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.

gregbell avatar gregbell commented on May 22, 2024

@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.

georgekitchit avatar georgekitchit commented on May 22, 2024

Has the ability to be able to add to existing index actions been added?

from activeadmin.

akashkamboj avatar akashkamboj commented on May 22, 2024

@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.

RobertLowe avatar RobertLowe commented on May 22, 2024

Bump, +1, this is simple and a common use case.

from activeadmin.

nickpellant avatar nickpellant commented on May 22, 2024

I'd like to see this implemented too.

from activeadmin.

jamesduncombe avatar jamesduncombe commented on May 22, 2024

This would be great!

from activeadmin.

marvwhere avatar marvwhere commented on May 22, 2024

+1

from activeadmin.

jarrodrobins avatar jarrodrobins commented on May 22, 2024

+1!

from activeadmin.

BaylorRae avatar BaylorRae commented on May 22, 2024

+1

from activeadmin.

gregbell avatar gregbell commented on May 22, 2024

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.

lukei8ii avatar lukei8ii commented on May 22, 2024

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.

seanlinsley avatar seanlinsley commented on May 22, 2024

Specifically it was #1834

from activeadmin.

lukei8ii avatar lukei8ii commented on May 22, 2024

Thanks @macfanatic and @daxter

from activeadmin.

seanlinsley avatar seanlinsley commented on May 22, 2024

You have to pass defaults: true when calling actions
EDIT: misread what you were asking

from activeadmin.

bartezic avatar bartezic commented on May 22, 2024

Thanks a lot!

from activeadmin.

AlexeyMK avatar AlexeyMK commented on May 22, 2024

@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.

seanlinsley avatar seanlinsley commented on May 22, 2024

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.

AlexeyMK avatar AlexeyMK commented on May 22, 2024

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:

  1. Add an example with multiple links that uses +es
  2. 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.

 avatar commented on May 22, 2024

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.

msiraj83 avatar msiraj83 commented on May 22, 2024

Normaly when we add default_action command... Then name for the column is empty... Is any way to rename the column....???

from activeadmin.

alexventuraio avatar alexventuraio commented on May 22, 2024

@krtschmr @danishsatkut Mmm it does not work for me!

from activeadmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.