Hello,
I’m having trouble setting up Forest using the forest_liana gem, version 5.2.1 (having the same issue with 4.2.0). The problem occurs on development, staging and production.
Expected behavior
forest_liana should respond to all XHR requests from Forest with the asked content.
Actual behavior
Count requests work correctly as well as edits and creates but all index requests trigger “No template found for ForestLiana::UserSpace::CompanyController#index, rendering head :no_content”, with differences in the controller of course depending on the resource I’m trying to access.
Failure Logs
12:30:54 rails.1 | Started GET "/forest/Company?fields%listOfFieldsRedacted" for 127.0.0.1 at 2020-07-20 12:30:54 +0200
12:30:54 rails.1 | Processing by ForestLiana::UserSpace::CompanyController#index as JSON
12:30:54 rails.1 | Parameters: {"fields"=> listOfFieldsRedacted, "page"=>{"number"=>"1", "size"=>"15"}, "searchExtended"=>"0", "sort"=>"-id", "timezone"=>"Europe/Brussels", "collection"=>"Company"}
12:30:54 rails.1 | No template found for ForestLiana::UserSpace::CompanyController#index, rendering head :no_content
12:30:54 rails.1 | Completed 204 No Content in 1ms (ActiveRecord: 0.0ms | Allocations: 637)
12:30:54 rails.1 |
12:30:54 rails.1 |
12:30:54 rails.1 | Started GET "/forest/Company/count?listOfFieldsRedacted" for 127.0.0.1 at 2020-07-20 12:30:54 +0200
12:30:54 rails.1 | Processing by ForestLiana::UserSpace::CompanyController#count as HTML
12:30:54 rails.1 | Parameters: {"fields"=>listOfFieldsRedacted, "searchExtended"=>"0", "timezone"=>"Europe/Brussels", "collection"=>"Company"}
12:30:54 rails.1 | [active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.05ms)
12:30:54 rails.1 | Completed 200 OK in 2ms (Views: 0.4ms | ActiveRecord: 0.5ms | Allocations: 701)
12:30:54 rails.1 |
12:30:54 rails.1 |
12:30:55 rails.1 | Started GET "/forest/User?fields%5BlistOfFieldsRedacted" for 127.0.0.1 at 2020-07-20 12:30:55 +0200
12:30:55 rails.1 | Processing by ForestLiana::UserSpace::UserController#index as JSON
12:30:55 rails.1 | Parameters: {"fields"=>listOfFieldsRedacted, "page"=>{"number"=>"1", "size"=>"15"}, "searchExtended"=>"0", "sort"=>"-id", "timezone"=>"Europe/Brussels", "collection"=>"User"}
12:30:55 rails.1 | No template found for ForestLiana::UserSpace::UserController#index, rendering head :no_content
12:30:55 rails.1 | Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 1112)
12:30:55 rails.1 |
12:30:55 rails.1 |
12:30:55 rails.1 | Started GET "/forest/User/count?fields%5BlistOfFieldsRedacted" for 127.0.0.1 at 2020-07-20 12:30:55 +0200
12:30:55 rails.1 | Processing by ForestLiana::UserSpace::UserController#count as HTML
12:30:55 rails.1 | Parameters: {"fields"=>listOfFieldsRedacted, "searchExtended"=>"0", "timezone"=>"Europe/Brussels", "collection"=>"User"}
12:30:55 rails.1 | [active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.05ms)
12:30:55 rails.1 | Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.5ms | Allocations: 734)
Context
Please provide any relevant information about your setup.
- Gem Version: 5.2.1 and 4.2.0
- Rails Version: 6.0.3
- Project Name: JobTitle.io
By digging in the Gem’s code, I found out that the problem happens here : https://github.com/ForestAdmin/forest-rails/blob/4fabfb30266a121a9bc80ac3e667afe129ec9150/app/controllers/forest_liana/resources_controller.rb#L38
If I comment the respond_to block and just write return render_jsonapi(getter)
, it works. Of course this will prevent me from exporting CSVs etc. When I log the “Accept” header in that exact spot it gives me “application/json” which should trigger the JSON response on its own.
Any idea on why that might happen? I suppose it has troubles detecting the format to use in the response but what could be the cause?
EDIT : I solved it by changing mount ForestLiana::Engine => '/forest'
to mount ForestLiana::Engine => '/forest', defaults: { format: 'json' }
in my routes.rb file, which circumvents the bug since it will default to rendering JSON.