lorint / brick

Auto-generate models, views, controllers, and routes in a Rails app based on database structure
Other
269 stars 8 forks source link

strange error #6

Closed iatfrepo closed 1 year ago

iatfrepo commented 1 year ago

Hi Lorin I managed to setup a Ruby app on the Northwind db with Brick and ActiveAdmin. Everything runs fine but after I customized a little models and resources I got this strange issue. If I go to Orders in AA all is fine (see attachment#1) then if I click on the 'brick' icon I get an error (see attachment#2). I also attach a zip with models and resources.

Thank you Sergio La Marca 2023-05-04 15 00 20 localhost 49508c26a259 2023-05-04 15 01 36 localhost e9cf29347ec7 admin.zip

lorint commented 1 year ago

Oh interesting! If descrips ends up nil then on line 98 right before this it may write out to the terminal:

Caught it in the act for obj / status_id

or something similar. Would be great to see if that's showing up in the terminal.

Have added the orders_status, orders_tax_status, and inventory_transactions tables to a Northwind database and set up the models like you have, and so far mine is working:

Screenshot 2023-05-04 at 16 08 57

Because the word "status" is one of those that pluralises weirdly, I did try setting up an entry in the inflections.rb file to see if that might be part of it:

# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.uncountable %w(orders_status orders_tax_status)
end

Ended up with a kinda similar error as to what you describe when rendering orders. Looking into pluralisation and such a bit further now.

lorint commented 1 year ago

Heya @iatfrepo -- looks this overly-ambitious set of code designed to set @_brick_model when it is nil was preventing a couple of admin panels from working:

https://github.com/lorint/brick/blob/dcaa57217204dd0bd73c00c0d948d6f47537ae61/lib/brick/frameworks/rails/engine.rb#L670-L671

Have dialed this back (thankfully it was never a part of a release, only here in the unreleased code), and also added a little more resilience to #brick_grid so that in the event the belongs_to descriptions are absent, it keeps going instead of having the error surface that you have seen. This has made its way into release 1.0.137 of the gem. To update an existing Rails project, you can run bundle update brick and it should pull this newer version and put it into your Gemfile.lock.

Thanks for your contribution!

iatfrepo commented 1 year ago

Hi Lorin great job as always! Thanks.