Started GET "/forest/User/175/all_cards?timezone=Europe%2FSamara&fields%5BCard%5D=card_type%2....mber%5D=1&page%5Bsize%5D=15&sort=-id" for 127.0.0.1 at 2023-01-10 14:52:39 -0500
Started GET "/" for 127.0.0.1 at 2023-01-10 14:52:40 -0500
Processing by HomeController#show as JSON
Parameters: {"home"=>{}}
Completed 500 Internal Server Error in 14ms (ActiveRecord: 0.0ms | MongoDB: 0.0ms | Allocations: 5181)
## Correct behavior
Started GET “/forest/User/175/relationships/user_profiles/count?fields%5BUserProfile%5D=user%2…system_role%5D=name&fields%5Bproject%5D=name&timezone=Europe%2FSamara” for 127.0.0.1 at 2023-01-10 14:52:28 -0500
Processing by ForestLiana::AssociationsController#index as JSON
Processing by ForestLiana::AssociationsController#count as JSON
Context
Project name: …
Team name: …
Environment name: …
Agent type & version: …
Recent changes made on your end if any: …
Hello,
I am trying to implement a simple Smart Relationship by following this guide:
User has_many UserProfiles
UserProfile has_many Cards
I am trying to add ‘All Cards’ in the Users collection Related Data:
Started GET "/forest/User/175/all_cards?timezone=Europe%2FSamara&fields%5BCard%5D=card_type%2....mber%5D=1&page%5Bsize%5D=15&sort=-id" for 127.0.0.1 at 2023-01-10 14:52:39 -0500
Started GET "/" for 127.0.0.1 at 2023-01-10 14:52:40 -0500
Processing by HomeController#show as JSON
Parameters: {"home"=>{}}
Completed 500 Internal Server Error in 14ms (ActiveRecord: 0.0ms | MongoDB: 0.0ms | Allocations: 5181)
From what I can quickly see in your failure logs, the request was sent to ‘forest/User/:user_id/all_cards’ instead of ‘forest/User/:user_id/relationships/all_cards’.
I’m sorry, I didn’t understand your issue at first. Can you confirm me that your endpoint ‘forest/User/:user_id/relationships/all_cards’ is working as it should and the issue is that the query sent by your browser is made to the following url: 'forest/User/:user_id/all_cards’ ?
Would you please share with me the name of your project and the environment on which you are working ?
I changed the route, and it is still not working, but the errors are different:
Started GET "/forest/User/4/all_cards?timezone=Europe%2FSamara&fields%5BCard%5D=card_...=name&page%5Bnumber%5D=1&page%5Bsize%5D=15&sort=-id" for 127.0.0.1 at 2023-01-12 08:46:33 -0500
Processing by Forest::UsersController#all_cards as JSON
Parameters: {"timezone"=>"Europe/Samara", "fields"=>{"Card"=>"card_..."name"}, "page"=>{"number"=>"1", "size"=>"15"}, "sort"=>"-id", "user_id"=>"4"}
[2023-01-12 08:46:33] Forest 🌳🌳🌳 Smart Action execution error: undefined method `[]' for nil:NilClass
...
[2023-01-12 08:46:33] Forest 🌳🌳🌳 Smart action execution error: Unable to retrieve the smart action id.
[2023-01-12 08:46:33] Forest 🌳🌳🌳 Find Collection error: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return"
class Forest::User
include ForestLiana::Collection
collection :User
# User to Cards HasMany Smart Relationship
has_many :all_cards, type: ['String'], reference: 'Card.id'
end
# routes:
namespace :forest do
# Smart Relationships
get '/User/:user_id/all_cards' => 'users#all_cards'
end
I have redacted all of the other actions and routes from there since they all work fine.
I just tested this again by temporarily commenting out all smart fields/actions from the Users collection, as well as commenting out all of the other forest routes, and still failed with the same errors.
There is only one before_action in the controller, and I commented that out and tried again, but still failing with the same errors.
# routes:
require 'sidekiq/web'
require 'sidekiq/cron/web'
Rails.application.routes.draw do
mount Sidekiq::Web => '/sidekiq'
namespace :forest do
# Smart Relationships
get '/User/:user_id/all_cards' => 'users#all_cards'
end
I also simplified the ‘all_cards’ method, but made no difference.
I even added ‘debugger’ in the method definition in an attempt to debug (see params, etc.), but it looks like it is failing before reaching the method because I am not able to enter debug mode - just displays same errors.
def all_cards
debugger
user = User.find(params['user_id'])
...
Just to have more context, a basic has_many relationship has the following format: /forest/:collection/:id/relationships/:relation_name
but on a smartrelationship the format is /forest/:collection/:id/:relation_name (which we need to patch in the future)
more information here :
I’m sorry I still can’t reproduce your issue, however since you can’t reach the debugger, it looks like a route conflict.
Can you try to put the route definition /User/:user_id/all_cards first?
Have you also tried to call this route directly with a tool like postman or insomnia rest?
I think this was the issue - I completely glossed over that part of the guide, and have been using our regular users smart action controller, which extends ForestLiana::SmartActionsController
I am now able to enter debug mode inside the controller method definition, which means the route is working. I will do a complete test later today and will let you know how it goes.
I apologize for wasting your time with this - I should have paid more attention to the docs, and also that the failing route and your earlier links to your source code should have led me to take a closer look at that portion of the code.
Thanks again for all your help, and your patience!