Closed lcuevastodoit closed 3 years ago
Hey, yea, great question
You could do it in one of a few ways.
col :my_actions do |device|
link_to(device, device_path(device))
end
actions_col do |device|
dropdown_link_to('Disable', device_disable_url(device))
end
The drop down link to comes from effective_bootstrap
gem and builds the button group.
If the disable devise is set up as a member route in your routes, the datatables will just pick them up
resources :devices do
post :disable, on: :member
end
And make sure you have can(:disable, Device)
or whatever permissions to actually disable on that device.
If the route is present, and the config.authorization_method is true, the datatable actions_col will automatically display those member actions.
Hope this helps.
Have a great day!
Sorry, I almost have it with this DSL, thanks for the previous answers. If I have, in my model DeviceDatatatable.rb
How can I get the col value in the line # 2 pass as a param to the link_to helper in line # 5? And, How can I get the col value in the line # 3 pass as a param to the link_to helper in line # 5 too? 1.- datatable do 2.- col :dev_id 3.- col :zone_id 4.- col :my_actions do |device| 5.- link_to("Disable", device_disable_path(devid: dev_id, zone: zone_id)) 6.- end 7.- end
SOLVED: I just had to create one more sub-array element (add an extra column) from outside the model and before calling it from collection. Then I manipulated that extra column to create the button, something like this:
col :myactions do |value| dev_id = value[0].to_s zone_id = value[1].to_s link_to("Disable", device_disable_path(devid: dev_id, zone: zone_id)) end
Thanks again Matt !!
Hi and thanks for this gem, one question: I did not see it very clear in the documentation but I need to create some buttons for actions that do not belong to the traditional CRUD model. In ERB it is very simple since if my table data comes from @data which is an Array of Arrays, @data would be for example something like this: [["device01", "zone01", "value01"], ["device01", "zone02", "value02"]...]]
And then with an @data.each , I would create one or several buttons per table row on view, something like this:
<%= link_to "Disable", device _disable_url(devid: dev.id, zone: @zone_id), class: "btn btn btn-outline-danger btn-xs conspinner" %>>
How I can do something like this with this gem, and where would I do it?