I’ve been following the docs to set up a simple smart action (“show in app”) in my Forest Admin panel for my Rails app, but it’s not working!
I’ve tried a couple of ways now.
Ideally, it’s a GET request since I’m not changing any data, just opening a page within my app.
I have the following code.
In lib/forest_liana/collections/book.rb
:
action 'Show in app', type: 'single', endpoint: '/forest/actions/books/show-in-app', http_method: 'GET'
In config/routes.rb
:
namespace :forest do
get '/actions/books/show-in-app' => 'books#show_in_app'
end
mount ForestLiana::Engine => '/forest'
In app/controllers/forest/books_controller.rb
:
class Forest::BooksController < ForestLiana::SmartActionsController
def show_in_app
book_id = ForestLiana::ResourcesGetter.get_ids_from_request(params).first
render json: {
success: 'Success',
redirectTo: book_path(book_id),
}
end
end
When I attempt to use the action, I get the following failure in the console:
TypeError: Failed to execute ‘fetch’ on ‘Window’: Request with GET/HEAD method cannot have body.
I tried to find a way for the request to not send any data along with it and failed. If there’s a way to do that, I’d love to know.
In the meantime, I decided to just use the default POST
method to see if I could get the action working.
Once I got to the proper CORS
setup, to enable app.forestadmin.com
to make an API request to my localhost
, I get a 403 with the following error, whether I try and redirect to localhost
or an HTTPS ngrok tunnel link:
Filter chain halted as :check_permission_for_smart_route rendered or redirected
I’m not sure if this is related to user/role permissions on the smart action but the docs say this shouldn’t be a factor for development environment.
I’m on Rails 6.1, using forest_liana
6.4.
Thank you.