You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am really not sure what exactly is going on here, and I am pretty sure this is the edge case of the edge case scenarios.
I am implementing trestle in a legacy project here.
I have dozens of models that are pretty much all related.
We are adopting the use of Trestle focused on behavior rather than on "entities". What do I mean by that? We have several "admins" focused on specific actions we want users to take. (Example: I have an action which is "edit the user's address" - this links to customer/address_admin.rb and my form only allows users to alter address details)
OK so everything was going fine... My resources are all working beautifully with initializing them with Trestle.resource(:block_name, [scope: SomeScope], model: SomeModel)
I mean, until I ran into a problem with a specific Model.
Trestle.resource(:date_bulk_update,model: InvoiceGroup)domenudoitem:date_bulk_update,end# everything else is commentedend
Causes my server to crash. In the logs, the crash seems to be in app/models/invoice_group.rb and the next couple of lines suggest it has something to do with scopes in ActiveRecord
these are my scopes
scope:find_by_id_or_name,->(id){find_by('name = ? or id = ?',id,id.to_i)}scope:find_by_business_and_bank,lambda{ |business,bank|
joins(:businesses).where(businesses: {document: business.document}).where(bank: bank).order(created_at: :desc)}scope:monitored,lambda{ |bank|
ifbank.slug == 'bank_slug'where('invoice_groups.created_at >= ?',6.months.ago)elseallend}
If I comment or rename my scopes, my server spins up correctly
THIS CRASHES MY SERVER
# scopes edited to make it easier to readscope:find_by_id_or_name,->(id){find_by('name = ? or id = ?',id,id.to_i)}scope:find_by_business_and_bank,lambda{ |business,bank| ... }scope:monitored,lambda{ |bank| ... }
EITHER WORKS
# scopes edited to make it easier to readscope:afind_by_id_or_name,->(id){find_by('name = ? or id = ?',id,id.to_i)}scope:afind_by_business_and_bank,lambda{ |business,bank| ... }scope:amonitored,lambda{ |bank| ... }### OR# scopes edited to make it easier to read#scope :find_by_id_or_name, ->(id) { find_by('name = ? or id = ?', id, id.to_i) }#scope :find_by_business_and_bank, lambda { |business, bank| ... }#scope :monitored, lambda { |bank| ... }
Any idea of what may be going on?
The text was updated successfully, but these errors were encountered:
I've just tried reproducing this in a new Rails (8.0) app and wasn't able to. The only thing that I notice in your code that could be a cause is the trailing comma on your item line:
Trestle.resource(:date_bulk_update, model: InvoiceGroup) do
menu do
- item :date_bulk_update,+ item :date_bulk_update
end
# everything else is commented
end
If that doesn't help, could you please post the full error trace and your Trestle/Rails versions.
I am really not sure what exactly is going on here, and I am pretty sure this is the edge case of the edge case scenarios.
I am implementing trestle in a legacy project here.
I have dozens of models that are pretty much all related.
We are adopting the use of Trestle focused on behavior rather than on "entities". What do I mean by that? We have several "admins" focused on specific actions we want users to take. (Example: I have an action which is "edit the user's address" - this links to customer/address_admin.rb and my form only allows users to alter address details)
OK so everything was going fine... My resources are all working beautifully with initializing them with
Trestle.resource(:block_name, [scope: SomeScope], model: SomeModel)
I mean, until I ran into a problem with a specific Model.
Causes my server to crash. In the logs, the crash seems to be in app/models/invoice_group.rb and the next couple of lines suggest it has something to do with scopes in ActiveRecord
these are my scopes
Funny/Odd things:
Depending on how I instance InvoiceGroup:
This Crashes:
This Works:
If I comment or rename my scopes, my server spins up correctly
THIS CRASHES MY SERVER
EITHER WORKS
Any idea of what may be going on?
The text was updated successfully, but these errors were encountered: