this my app/admin/author- enter image description here
How can i change delete button in admin/authors (index)
I need change only confirm message
How can i do this?
I try:
actions :all, :except => [:destroy] and then add custom actions default: true and create custon button, and its work i get custom message, but i can't destroy some author, because when i actions :all, :except => [:destroy], this delete route for deleting author
If relying on jquery does not bother you, add this to app/assets/javascripts/active_admin.js
$(document).ready(function () {
$('a.delete_link').data('confirm', 'is this what you really want?');
/* narrow down with selector for specificity */
$('table#index_table_authors a.delete_link').data('confirm', 'must this author really be destroyed?');
});
Or
Related
I have a nested resource in Active Admin which shows all SupportSessions (like meetings) for a particular SupportAllocation (which defines a teacher-pupil relationship):
ActiveAdmin.register SupportSession do
belongs_to :support_allocation
On my index page, I'd like a button at the top that the user can click (like they can click 'New Support Session'), which then executes a custom method which sends an email using ApplicationMailer. There is no 'page' where the button goes to - it just redirects back to the current index page with a message indicating success or otherwise.
I can get the 'Request Approvals' button to appear on the index page with this code:
# Adds a new button
action_item only: :index do
link_to 'Request approvals', send_for_approval #custom method
end
But obviously this raises an exception:
undefined local variable or method `send_for_approval'
Because I haven't defined this custom method anywhere.
I've created my mailer class but I'm not sure how to 'connect' it to my resource. I realise this will involve a new route of some sort, or use the existing 'put' method. I'd need to hand the current SupportAllocation ID to the method, so it knows which records/data to deal with when it sends email messages.
Any tips on how do I do create a button that runs this custom method + parameter? Where do I define this new custom method?
Thank you for your help.
You should code the action first, in your file:
member_action :send_for_approval, method: :patch do
# send your email here you can access to :resource which is your record
YourMailer.with(support_session_id: resource.id).your_email.deliver_now
# redirect to your admin index or show path
end
Then rails routes will give you the correct path to it so you can pass it to action_item, it will look something like that:
action_item only: :index do
link_to 'Request approvals', send_for_approval_admin_support_session_path, method: :patch
end
References:
https://activeadmin.info/8-custom-actions.html#member-actions
https://activeadmin.info/8-custom-actions.html#action-items
I'm building a RoR app where each record has a unique, 7 character token (hex). I would like to create link on a page where a user can provide that token and be brought to the edit path for that record. I've scoured the WWW and can't seem to find a clean method to accomplish this task.
Any ideas?
I realize I run a slight risk of duplication, but this will be a novelty app more than anything.
Vanity URLs in Rails
For if you want to be able to navigate to /model/5na09zn instead of /model/{id}:
1. config/routes.rb
resources :model
--- becomes --->
resources :model, :except => ['show', 'update', 'destroy']
get 'posts/:hex_token' => 'model#show', :as => 'model'
put 'posts/:hex_token' => 'model#update'
delete 'posts/:hex_token' => 'model#destroy'
2. app/controllers/model.rb
Do this for all show, update and destroy:
(Better yet, write a controller function to handle this automatically!)
def show
#model = Model.find(params[:id])
...
end
--- becomes --->
def show
#model = Model.find_by_hex_token(params[:model])
...
end
I would like to dynamically change the menu based on the permissions of the viewing user. I would like the superadmin user to have access to the normal Resource actions (index, show, update, etc). So when an admin clicks on a menu item, it would take them to the index of that resource. I would like to restrict the normal admin user to just viewing a specific show page.
The menu route for the superadmin would be: /admin/resource
The menu route for the normal admin would be: /admin/resource/id
I would also like to restrict normal admin access to the index view, or other resources that they don't have access to. I have been able to achieve both these things, but I have yet to be able to map a menu item to a specific show page. I know I could create a custom page and view, but I really would like to share the custom DSL for the show and edit pages between superadmin and the normal admin.
Anyone know how to make this happen.
Ok, so I figured a way to get what I want. I am not sure if exactly fulfills what I wanted. (meaning, it would be nice to create custom menu items that are mapped to specific resources)
I just overwrote the index controller action to redirect to the specific show page. Because the super admin needs access to the original Store resource, I had to alias it with :as.
ActiveAdmin.register Store, :as => 'My Store' do
menu :if => proc{ !current_user.is_admin? },
:label => 'My Store'
actions :show, :edit, :update
controller do
def index
redirect_to(admin_my_store_url(current_user.store))
end
end
end
Rails 2.3.11
In Rails, when you generate a scaffold, it creates index, show, edit, and new views for it, as well as a host of methods in the associated controller. How do I add my own view to the model?
For my Events model, I'd like to add /events/past to display all events that have already happened. When I just add
def past
end
to events_controller and create /views/events/past.html.erb, then go to site.com/events/past, it looks for an event with the ID "past".
If I add map.match '/events/past' => 'events#past' to routes.rb, it says I must specify the controller.
If that's changed to map.match '/events/past' => 'events#past', :controller => :events, I'm back with the same "Couldn't find Event with ID=past" error.
Thanks for helping out someone who's new to Rails!
Since this is the old Rails, I believe you must use:
map.match 'events/past', :controller => "events", :action => "past"
I believe what your missing is the :on => :collection bit. Then I bet the order isn't important.
I have an index page of elements, and I'm trying to implement a "Delete" button that will send a delete request to the controller with a list of the elements user has checked. So far I've done the following
#routes.rb
resources :messages, :except=>[:update,:edit] do
member do
delete :delete_all
end
end
#index.html.haml
=button_to "Delete", {:controller=>"messages", :action => "delete_all"}, :method=>"delete"
...
=check_box "message", "mark"
#messages_controller.rb
def delete_all
....
end
I've been trying to do it RESTfully, but I've come across routing errors and other tricky problems. Like, for instance, when I used pure AJAX I come across the problem with the before_filter that wants to authenticate the user, and it doesn't let my request through.
Can anyone explain to me what I need to do? How do I implement this button?
Try using collection do for the route, since this is how you use it in your view (without an :id).