Reputation: 49
I am using active admin gem to have a admin console for my ruby on rails application. I am having a problem where i want to have multiple custom actions to every item on index page just like View,Edit, Delete. But when adding custom action only the last one is displayed instead of all.
index do
column 'Instructor Name',:user
column 'Email Address', :email
column 'Phone Number', :phone
column 'website', link_to 'google', 'www.google.com'
column :bio
actions defaults: false do |application|
if application.user.instructor == 2
button_to 'Disapprove', instructor_deny_user_path(application.user.id), method: :put
else
button_to 'Approve', instructor_approve_user_path(application.user.id), method: :put
end
link_to "resume",getresume_instructor_applications_path(id: application.id)
end
end
Only resume link is shown instead of Approve/Disprove and resume
What am i doing wrong
Upvotes: 3
Views: 2836
Reputation: 54
For v1.3 the solution
actions defaults: false do |application|
if application.user.instructor == 2
item 'Disapprove', instructor_deny_user_path(application.user.id), method: :put
else
item 'Approve', instructor_approve_user_path(application.user.id), method: :put
end
item "resume", getresume_instructor_applications_path(id: application.id)
end
is what worked for me - thanks to @littleforest 's comment
You can also add , class: "member_link"
for the spacing
Upvotes: 1
Reputation: 3073
If you have ActiveAdmin >= 1.0.0.preX, you can do this:
actions defaults: false do |application|
if application.user.instructor == 2
action_item 'Disapprove', instructor_deny_user_path(application.user.id), method: :put
else
action_item 'Approve', instructor_approve_user_path(application.user.id), method: :put
end
action_item "resume", getresume_instructor_applications_path(id: application.id)
end
If you use a 0.6.x:
actions defaults: false do |application|
if application.user.instructor == 2
text_node link_to 'Disapprove', instructor_deny_user_path(application.user.id), method: :put
else
text_node link_to 'Approve', instructor_approve_user_path(application.user.id), method: :put
end
link_to "resume", getresume_instructor_applications_path(id: application.id)
end
Upvotes: 6
Reputation: 924
Try put your approve/disapprove links in columns like this,
column 'action' do |application|
application.user.instructor == 2 ? button_to 'Disapprove', instructor_deny_user_path(application.user.id), method: :put : button_to 'Approve', instructor_approve_user_path(application.user.id), method: :put
end
And Default link for resume as it is.
actions defaults: false do |application|
link_to "resume",getresume_instructor_applications_path(id: application.id)
end
Upvotes: 0