Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arnaudbesnier/e1401434a27870876d4ad5d9fa591647 to your computer and use it in GitHub Desktop.
Save arnaudbesnier/e1401434a27870876d4ad5d9fa591647 to your computer and use it in GitHub Desktop.
Forest Rails - Admin API - Override on the records list for a Smart Action context
# /lib/forest_liana/collections/movie.rb
class Forest::Movie
include ForestLiana::Collection
collection :Movie
action 'Approve comment', fields: [{
field: 'comment',
type: 'Number',
reference: 'Comment.id',
widget: 'belongsto select'
}]
end
# /lib/forest_liana/controllers/comment_controller.rb
if ForestLiana::UserSpace.const_defined?('CommentController')
ForestLiana::UserSpace::CommentController.class_eval do
alias_method :index_default, :index
def index
if request.params && !request.params['searchExtended'].nil?
# NOTICE: Seach for collection list, keep the default behaviour.
index_default
else
movie_id = request.headers.env['HTTP_REFERER'].match(/record\/[^\/]*\/([^\/]*)\//)
movie_id = movie_id[1] if movie_id && movie_id[1]
comments = Comment.where({ movie_id: movie_id })
render json: serialize_models(comments)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment