Skip to content

Instantly share code, notes, and snippets.

@marinalohova
Created March 14, 2012 19:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save marinalohova/2039001 to your computer and use it in GitHub Desktop.
Save marinalohova/2039001 to your computer and use it in GitHub Desktop.
Custom action for RailsAdmin
require 'rails_admin/config/actions'
require 'rails_admin/config/actions/base'
module RailsAdminApproveReview
end
module RailsAdmin
module Config
module Actions
class ApproveReview < RailsAdmin::Config::Actions::Base
register_instance_option :visible? do
authorized? && !bindings[:object].approved
end
register_instance_option :member do
true
end
register_instance_option :link_icon do
'icon-check'
end
register_instance_option :controller do
Proc.new do
@object.update_attribute(:approved, true)
flash[:notice] = "You have approved the review titled: #{@object.title}."
redirect_to back_or_index
end
end
end
end
end
end
@dangluan
Copy link

I coped this snippet code and save into lib dir of my app and restart server and Error appear

    undefined local variable or method `approve_review' for RailsAdmin::Config::Actions:Module (NameError)

@dangluan
Copy link

ok . you need add this line to your rails_admin.rb in initializers

    require Rails.root.join('lib', 'rails_admin_approve_review.rb')

@heridev
Copy link

heridev commented Oct 2, 2014

I think the following lines are not needed

module RailsAdminApproveReview
end

It works for me without those lines Am I wrong? :) btw thanks for the example code

@rscardinho
Copy link

The ApproveReview module doesn't have the register method:

RailsAdmin::Config::Actions.register(self)

I added this and it's working now

@prakash89
Copy link

How can i add route in Rails admin view:

in views/rails_admin/cp_tabes.html.erb added below link.

<%= link_to 'Download Asset Report'.html_safe, asset_report_path(:format => 'csv'), :class => 'anchor-download-report-color' %>

i got undefined method `asset_report_path' for #<#Class:0x007fb02e8df348:0x007fb02e36e210>

thank you.

@norcali
Copy link

norcali commented Apr 3, 2017

you have to add main_app.route_path or rails_admin.route_path or they won't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment