Hey there Came here from Twitter after
# avo-2
f
Hey there! Came here from Twitter after seeing @lemon-wall-20836's tweet (apologies in advance!!) I ran into an issue when doing
RAILS_ENV=production rails s
and trying to edit an
Array
field using the
fields as: :tags
on the Avo resouce. The strange thing is... locally it seems to persist the tags as an Array correctly. However, on production, it doesn't. I can't seem to find a way to override the controller to do a
binding.pry
to see exactly what's going on. Does anyone know?
l
Hey Gabriel
> However, on production, it doesn't. does it save anything? does it delete/modify the current value?
> I can't seem to find a way to override the controller You should be able to override any controller methods. That's why every resource generated has a controller too
UserResource
->
Avo::UsersController
would you be able to send over some code in a reproduction repository so we can have a look?
it's definitely a case to look at some code
f
seems to ignore the new value entirely
l
f
ah, wait, is
acts_as_taggable
absolutely necessary?
l
no. it's not
f
For my case, I'm just trying to edit this
t.string :images, array: true, default: []
l
that should work!
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123211385267048508/CleanShot_2023-06-27_at_19.20.512x.png

Here's what im doing!
l
can you share your model too?
f
yep one sec!

https://cdn.discordapp.com/attachments/1123209804761010206/1123211587164057630/CleanShot_2023-06-27_at_19.21.432x.png

@lemon-wall-20836 is it late where you are? i feel terrible making you stay up if so haha
l
no. it's 2 pm
everything looks in order
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123211892807192656/CleanShot_2023-06-27_at_19.22.562x.png

here's schema as well just in case!
ooh thank goodness haha
l
ok. let me try to reproduce it
f
From
Gemfile.lock
, im on
avo (2.35.0)
l
cool. thanks
f
really odd haha
i could try to downgrade a version to see if there was a regression 🤔
n
I'm using the same thing... working fine
Copy code
ruby
t.text :blade_colors, array: true, default: []
Copy code
ruby
field :blade_colors, as: :tags
l
Copy code
ruby
class CreateTools < ActiveRecord::Migration[6.1]
  def change
    create_table :tools do |t|
      t.string :name
      t.string :images, array: true

      t.timestamps
    end
  end
end

# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::ToolsController < Avo::ResourcesController
end

class Tool < ApplicationRecord
end
https://cdn.discordapp.com/attachments/1123209804761010206/1123213746656006215/CleanShot_2023-06-27_at_14.30.06.mp4
n
which version of PG are you using locally & on production ?
f
let me check
l
yeah. that might be interesting to know
n
also, can you check the logs on production ?
l
I mean, if it's working locally and not working on production... my hunch is that there's a configuration issue
f
From browser

https://cdn.discordapp.com/attachments/1123209804761010206/1123214281874350080/CleanShot_2023-06-27_at_19.32.212x.png

n
rails logs not network logs..
f
PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg20.04+1) on aarch64-unknown-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
yeah gimme a sec!!

https://cdn.discordapp.com/attachments/1123209804761010206/1123214761023250532/CleanShot_2023-06-27_at_19.34.152x.png

is there anyway i could do a before_create callback in Avo Controller?
l
yes
f
and then print out some values to see whats going on
f
Re: config issue, any guesses on what might be it?
l
TL;DR; - you create a concern where you add the action and the method - in the initializer attach that concern to the desired controller
hmm, not really
n
( are you using RoR with a SOL project ? )
l
another configuration change might be in Rails' environment files
production.rb
vs
development.rb
.
f
What's SOL?
n
solana ? :-p
since your name is **SOL**Happy
f
ahhh that might be
AHHA oops, im out of crypto 😛 this was just an old handle haha
Back to web2 lol
n
makes sense 😂😂😂
f
hahaha 🤣 checking production config now
i've only kept to rails 7 defaults tho
l
oh, ok
f
Only thing i changed was
Copy code
# Lograge
  config.lograge.enabled = true
  config.lograge.formatter = Lograge::Formatters::Json.new
l
so it's a new Rails 7 app
f
yep 7.0.5
l
it's weird, because it should just work
f
Ok, im thinking maybe the weird issue could be... I'm connecting production to Postgres hosted by Supabase?
and...

https://cdn.discordapp.com/attachments/1123209804761010206/1123216148717121536/CleanShot_2023-06-27_at_19.39.502x.png

This is
database.yml
Well, unless the prepared statements are messing things up?
haha
thats quite a stretch tho
l
hmmm. IDK. I never worked with prepared statements
f
I set it to false as the url points to pgbouncer
n
me too.. no idea what this is
f
hahaha
actually lemme turn this off and see if it changes anything
nope, no difference haha
l
have you pushed to prod so fast?
or you're running it locally with
RAILS_ENV=production
?
f
yup!
running it locally with that flag
l
well, try it in production
live on the server
so
RAILS_ENV=development
runs ok, right?
f
yep it does
strange tho haha
l
ok. so let's stop trying to debug a scenario that nobody will use (
RAILS_ENV=production
locally)
push it to production and let's see if that happens
f
redeploying now
Im not an expert with rails so don't mind me asking this: any thing bad with running
RAILS_ENV=production
to debug potential issues on prod?
or whats a better way around dev workflows here haha
l
nothing wrong, but because of how many things are in play, there could be misconfigurations in many places
what I do is set up another server (or the same server, but different location) with a different URL (staging.example.com) and test things there
f
usually, if RAILS_ENV=production doesn't work locally, then its also probable production will fail actually right?
l
and run it as
production
env
not necesarily
you gotta ask yourself "what am I trying to test here" that things run as close to production as possible, right? but on your own machine you might have different gem versions than in production, different connections, and soem gems might read configurations differently than expected, etc.
the easiest way to test production environments is to have them deployed on a server that mimics your actula prod environment
f
ahh so true. makes sense!
l
for example, when you run
bundle install
locally it will install gems that should run in
developmenr
and
test
environemnts, and on production you'd run
bundle install --without development test
f
goodness haa, maybe the better way then is to pick the other evil, Docker lol
true true. TIL!
l
that's a way to do it, but there's a deep end there too. you'll have to deploy using a docker image very similar to that too
I like to run everything native on my machine
99% of the time, things work in prod as expected
f
same here actually!
l
and there's a better dev-experience
f
Ok! i got production to deploy!
doens't work either 😦
checking logs on prod now
l
this is weeeeird 😛
f
yeee
ill need to disable lograge
l
I tried using 1,2,3 value
do that for a second please
f
does it work for you?
l
yeah 🙂
f
dang haha
i got super unlucky here then
first try with Avo 🤣
l

https://cdn.discordapp.com/attachments/1123209804761010206/1123220418774446160/CleanShot_2023-06-27_at_14.56.38.gif

lol. it happens
f
was a good ole adminstrate user aaha
l
now you got me curious
I don't believe you want to go back 😛
f
im going to try the controller overriding
l
did the logs give some indication of something?
f
haha i'd love not to. because of turbo + stimulus support on Avo. and pricing yearly seems good i'd actually pay for it if i was profitable
waiting for it to deploy
but going to override controller while waiting so we can figure this out faster haha
l
Copy code
ruby


    def fill_model
      # We have to skip filling the the model if this is an attach action
      is_attach_action = params[model_param_key].blank? && params[:related_name].present? && params[:fields].present?
      puts ['params->', params].inspect
      unless is_attach_action
        @model = @resource.fill_model(@model_to_fill, cast_nullable(model_params), extra_params: extra_params)
      end

      puts ['@model->', @model].inspect
    end
add this to the
Avo::ToolsController
just like that
it should
puts
out the @model after it's filled
f
oooh
let me try!

https://cdn.discordapp.com/attachments/1123209804761010206/1123221549831426079/CleanShot_2023-06-27_at_20.01.152x.png

getting this now
hang on
wrong file
lol

https://cdn.discordapp.com/attachments/1123209804761010206/1123222055811289178/CleanShot_2023-06-27_at_20.03.142x.png

i think we found the issue
its not sending an array input
but a string instead
l
that's fine
change the
puts
with
Rails.logger.debug
Rails.logger.debug ['@model->', @model].inspect
f
on it 😄

https://cdn.discordapp.com/attachments/1123209804761010206/1123222472641237012/CleanShot_2023-06-27_at_20.04.562x.png

l
can you try to update the name and send the logs?
so is this the whole model? no associations or anything?
f
yep zero associations
its literally the only table in DB
haha
l
pfff. this is weird AF
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123223279667249252/CleanShot_2023-06-27_at_20.08.062x.png

l
did the name change?
I don't see it in the logs
f
test NEW
added a nEW
you meant to change the value right?
l
hmm, maybe those logs aren't showing the SQL updates
yes. you did right
I was curious about the sql updates, but I think in production those are not visible
let me research that setting
config.log_level = :debug
add this to
production.rb
and redeploy please
f
yep doing this 😄
l
thanks!
:))
f
thanks for helping too
sorry this is taking ur time!
l
no worries. thanks for taking the time.
I'm curious what the issue is so others don't run into it too
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123224654342012988/CleanShot_2023-06-27_at_20.13.132x.png

l
hmmm, it's not trying to update the images
f
sorry fixed logs

https://cdn.discordapp.com/attachments/1123209804761010206/1123224779122561105/CleanShot_2023-06-27_at_20.14.082x.png

here's the full
l
thinking...
f
thinking too
haha
i could add a validator to model
and see if it throws error
if it does, then the issue is probably between view (how form was rendered and passing data to controller), and controller (how its processing the values)
ok maybe that doesnt make sense

https://cdn.discordapp.com/attachments/1123209804761010206/1123226108096167936/CleanShot_2023-06-27_at_20.19.272x.png

l
it's weird that it's inly happening in prod
f
could this be a possible issue?
it says permitted: false
how does avo controllers handle strong params?
l
it fetched them from the fields
where does it say that?
I don't see it here
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123226382797914234/CleanShot_2023-06-27_at_20.20.292x.png

found it here
HAHA
one sec
l
that's fine
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123226451584483338/CleanShot_2023-06-27_at_20.20.472x.png

sharing full tmux
l
because we just
puts
the
params
f
ahhh
l
that instance is not used by Avo
f
got it 😄
ok btw
l
ok. let's try something else
f
if i edited it via console
it shows up
and the tags are populated accordingly
so the issue has to be from controller and view haha
l
add a new column called
others
(or whatever) and add
field :others, as: :tags
f
generating migration now
l
just to rule that out
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123227085620641884/CleanShot_2023-06-27_at_20.23.182x.png

sorry
array: true

https://cdn.discordapp.com/attachments/1123209804761010206/1123227166855930010/CleanShot_2023-06-27_at_20.23.382x.png

l
yup
you can also add
default: []
but shouldn't matter
f
we could try to not include it and see if its the issue too
im thikning it might be why

https://cdn.discordapp.com/attachments/1123209804761010206/1123227642037014620/CleanShot_2023-06-27_at_20.25.302x.png

not working either

https://cdn.discordapp.com/attachments/1123209804761010206/1123228029137715261/CleanShot_2023-06-27_at_20.27.022x.png

l
where are you deploying? 😅
f
l
ok
f
i could try render if it makes a diff
l
well.... we exhausted all other options :))
f
haha sorry 😦
l
if it's easy, try it
f
wondering if its an Avo issue tho
and really curious how you would fix it 😛
l
I have one more idea
can you check the database see what is the value of the column?
the prod one
one more add
self.extra_params = [:images, tool: [:images]]
to the
ToolResource
f
trying now!
l
if that doesn't work, try
field :images, as: :text
and see if that updates it
BTW.... are you using the
community
or
pro
license?
f

https://cdn.discordapp.com/attachments/1123209804761010206/1123232438735351818/CleanShot_2023-06-27_at_20.44.322x.png

https://cdn.discordapp.com/attachments/1123209804761010206/1123232439112843347/CleanShot_2023-06-27_at_20.44.222x.png

community 😦
is this only for pro?
l
yes. it's for
pro
f
ahhh
is that why it doesnt work
haha
l

https://cdn.discordapp.com/attachments/1123209804761010206/1123232609321877604/CleanShot_2023-06-27_at_15.45.162x.png

f
aaahhhh
oh dang 😦
l
you can start a trial and get a license key and try it out
at least we got to the bottom of it...
f
HAHA so sorry if the cause was really just the requirement being a license key
l
no worries. we should surface that a bit better
f
btw it kinda works after what you told me to add

https://cdn.discordapp.com/attachments/1123209804761010206/1123233076240207952/CleanShot_2023-06-27_at_20.47.002x.png

l
hmm... yeah. I don't provide guarantees for that 🙂
can I ask you something?
f
yee?
l
could you go back to that tweet and say something about that. I don't want people to think that there's something wrong with Avo
f
i'd be happy to get the Pro if i was making money haha. but right now ill have to be careful about spending – just got laid off a month ago so im pushing hard to build a profitable product atm
ye defo! will say there's the best support
l
I know what you mean
I had a similar path with Avo
f
you're doing amazing! i told a fellow rubyist friend whoever made Avo was a genius
its like the sidekiq version of admin panels
haha the amazing thing about rails is tools around making dev life easier
i was going to either use adminstrate or retool lol
@lemon-wall-20836 lool after adding license key it works
🤣
l
pfff. we need to fix that
we should hide that field to make it more obvious
f
i think all pro stuff should be blocked from access maybe
because i spent so much hours on fixing this when i could be shipping other features 😢
that frustration is going to get to other users who just want to build fast (also the same users who will pay down the road)
l
I was under the impression that it was hidden
I know. it's frustrating for me too