[Resolved, Issue#369 on GitHub] Rails gem forest_liana cannot find a template to respond with : "Cannot reach your data."

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.

Hello @MartinV :wave: and welcome to our community :raised_hands:

Thank you for the detailed ticket, and the update :pray:

I don’t understand how rails could look for a template here. If I’m not mistaken, respond_to will look for the format requested by the client (web app), which in this case is JSON. This is a screenshot of a request I fire on my side for instance:


So you should be responded by either JSON or CSV.

May I ask you the request headers from the forest front end just to ensure headers are correct please ?

Thanks in advance.

Steve.

Hello and thanks for the response!

Indeed the problem seems to lie in the detection of that header.
The header sent by the front-end is correct “application/json” and when I did a log just before the “respond_to” part in the ForestLiana gem, it did log “application/json”.

Nevertheless, for whatever reason, it would not respond as JSON and then Rails default behaviour of looking for a view to render kicked in and made it fail.

When I removed the “respond_to” block and just rendered JSON all the time it worked of course.
So indeed the issue is responding correctly to the Accept header, but since I’m the only one (that I could find) experiencing this issue, I suppose something internal to our project is making this blow up?

Hi @MartinV

Thanks for the detailed ticket :pray:

Sadly, same as @Steve_Bunlon, no response header issue on my end either. Also, since it is liana related, I can’t get any informations on our side to find the source of the issue.

In my opinion, it is most likely related to a code change on your side (Since it seems like we’re not able to reproduce). However, since I can’t be sure, I would like to dig this a little more.

Is there, by any chance, a way we could potentially reproduce the behavior you are experiencing ?

Sorry for the inconvenience.

Hello !

After more testing, logging, debugging, it’s now clear that this is a problem inherent to our implementation, even though I cannot find what makes this happen. I’ll check a bit in the Rails code later on to try and understand !

When leaving the ForestLiana code as is, the CSV export works, just not the JSON formatted response.
By logging the content of the header I made sure that the header was indeed received as “application/json” by Liana.
I put a log statement inside the format.json block, which never appeared, so the block is indeed never called (I was thinking maybe if the content was nil Rails might fallback to something else even if it would be very very weird, you never know).
And most importantly : I put a respond_to block in one of our controllers to try it out, and indeed, the same problem appears.

So I think now it’s pretty clear that the problem is somewhere in our code, maybe it has something to do with the way we use netflix’s fast_jsonapi gem. I already spent a lot of time testing every line of the respond_to Rails code manually to see where this might come from but no luck yet :stuck_out_tongue:

Hello @MartinV :wave:

Thanks for sharing this well detailed feedback, it really helps out :+1:

Given your explanations, yes indeed, something else in the code might cause conflicts.

I hope you did find something out.

Steve.