Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Dr. Krieger posted:

This is perfect, the only thing I'd add is that of you only need your monkey patch in a few specific places is take a look at refinements. They are very weird because of how they handle scoping but they do work well when you need an explicit extension on a base class in only a few places and allow you to easily remove them later over just patching globally of you find a cleaner solution.

Yes, good call. I've had mixed results with refinements, but a couple of those times they were awesome. Worth consideration.

Adbot
ADBOT LOVES YOU

GeorgieMordor
Jan 23, 2015

kayakyakr posted:

Good response.


I think that's coming from the original requester. That's a string being encoded and wrapped as another string. So the request is being sent like:

post('endpoint', { json: JSON.stringify(someJson) })

Right? So that happens with a lot of libraries (I think including jquery) when you don't provide a content type with the ajax post. They automatically encode things as strings and don't leave them as JSON.

Only thing I can think of with Postman is that you're actually posting unparseable JSON for one reason or another.

What was sending this request was a hardware device (Android), so I put it on the radar for the Android dev team to send me some examples of how that payload is prepared and sent over.

In the meantime, I found I was able to address the issue by building a serializer to handle the problematic JSON and JSONB-powered fields. Working through some test cases now to see how it holds up.

Pollyanna
Mar 5, 2005

Milk's on them.


GeorgieMordor posted:

What was sending this request was a hardware device (Android), so I put it on the radar for the Android dev team to send me some examples of how that payload is prepared and sent over.

It should be the same as any other web request, unless it’s a matter of rendering on mobile.

kayakyakr
Feb 16, 2004

Kayak is true
Rails 6 went official yesterday: https://weblog.rubyonrails.org/2019/8/15/Rails-6-0-final-release/

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Which puts our massive codebase completely out of any support.

God I need a new job.

Sivart13
May 18, 2003
I have neglected to come up with a clever title

The Journey Fraternity posted:

Which puts our massive codebase completely out of any support.

God I need a new job.
you don't want your job to be upgrading the massive codebase to Rails 6?

what kind of job is this that has all the rails but not wants to upgrade it

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Sivart13 posted:

you don't want your job to be upgrading the massive codebase to Rails 6?

what kind of job is this that has all the rails but not wants to upgrade it

I would love to, if it weren't such a behemoth undertaking even to get it to 5.0. This codebase predates every single engineer, and was originally written by PHP devs writing their first Rails app.

kayakyakr
Feb 16, 2004

Kayak is true

The Journey Fraternity posted:

I would love to, if it weren't such a behemoth undertaking even to get it to 5.0. This codebase predates every single engineer, and was originally written by PHP devs writing their first Rails app.

1) you do need a new job
2) I don't have much empathy, at least for your company, because you didn't spend any time maintaining your codebase. If you had followed along with rails versions, it wouldn't be such a massive undertaking. The longer you put it off, the more painful it will become.

Also, Rails 4 to rails 6 isn't so hard. The codebase was mature enough by Rails 4.2 that there aren't many barriers to changing over.

GeorgieMordor
Jan 23, 2015
I'm stuck with using ActiveAdmin for a thing. It's fine, but when you're trying to do some more complex bits it gets really annoying.

I have two models associated via a join table. This join table was created using a migration, and while it has a working table and associations, does not have its own class in the Rails app. Maybe an issue?

So, schema is something like this:

systems(:id) -> systems_users(:system_id, :user_id) -> user(:id)

What I'm trying to do is alter a User form so that the joined records can be added / removed from within ActiveAdmin. I'm going around in circles trying to get this to work -- the only successful way I've been able to do this is by building a giant multi-select element, which will add and remove associations appropriately but is garbage for UI.

Alternately, ActiveAdmin shows these easily enough when using a has_many within the form, but it then changes the structure of the parameters on submit.

Displays and saves, but horrible to work with:
code:
 f.inputs 'Associated Systems' do
      f.input :systems, as: :select, input_html: { multiple: true }, collection: System.all.order(:name)
    end
Displays, but does not save:
code:
 f.inputs 'Associated Systems' do
      f.has_many :systems, heading: false do |m|
        m.input :id, as: :select, input_html: { multiple: false }, collection: System.all.order(:name)
      end
    end
I guess what I'm not understanding -- is there supposed to be some magical awareness of the systems_users table? All the documentation I'm reading says the has_many :systems pattern is the one to go for when using a join table, though the params on that submit are not reflective of any kind of :system_id or :user_id fields, which are expected to create a new record in the systems_users table.

When submitting I see a :systems_attributes parameter going through, which contains an array of ambigious :ids and values.

GeorgieMordor fucked around with this message at 19:56 on Aug 21, 2019

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

kayakyakr posted:

1) you do need a new job
2) I don't have much empathy, at least for your company, because you didn't spend any time maintaining your codebase. If you had followed along with rails versions, it wouldn't be such a massive undertaking. The longer you put it off, the more painful it will become.

Also, Rails 4 to rails 6 isn't so hard. The codebase was mature enough by Rails 4.2 that there aren't many barriers to changing over.

Oh for sure, I have none for them either. This place is very reactionary and only upgrades when things fall out of security fix windows, giving no time to do it outside of that small window.

(I'll stop the derail here)

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

How many Systems are there? Could you get away with checkboxes?

code:
 f.inputs 'Associated Systems' do
      f.input :systems, as: :select, input_html: { multiple: true }, collection: System.all.order(:name), as: :check_boxes
    end
I usually go for the multiple select widget, but wrapped in something like https://select2.org/ to make it sane to work with. It also opens the door to dark magicks like using it to dynamically search & populate against ActiveAdmin's built in Ransack support for when you get into the hundreds/thousands+ of records scale.

I'm a little fuzzy on this because I mostly avoid HABTM without an explicit join table model, but I think you would need one to use ActiveAdmin's has_many -- because you're essentially accept_nested_attributes_for'ing SystemsUsers

GeorgieMordor
Jan 23, 2015

The Milkman posted:

How many Systems are there? Could you get away with checkboxes?

code:
 f.inputs 'Associated Systems' do
      f.input :systems, as: :select, input_html: { multiple: true }, collection: System.all.order(:name), as: :check_boxes
    end

Sadly, no. Check boxes worked, but the System records are already over a couple hundred and will continue to grow. Honestly I did humor the idea just to save my sanity but the next issue was thinking about how to render the markup as columns and not just one vertical insane list of checkboxes.

The Milkman posted:

I usually go for the multiple select widget, but wrapped in something like https://select2.org/ to make it sane to work with. It also opens the door to dark magicks like using it to dynamically search & populate against ActiveAdmin's built in Ransack support for when you get into the hundreds/thousands+ of records scale.

I'm a little fuzzy on this because I mostly avoid HABTM without an explicit join table model, but I think you would need one to use ActiveAdmin's has_many -- because you're essentially accept_nested_attributes_for'ing SystemsUsers

Was about to do this too, though paused because this admin portion is used only by internal employees, and maybe 2-3 max at that, so principally I was getting annoyed tying in a jQuery plugin just for a single select form. No hate on Select2 -- that's actually been going strong for a while now.

To your point re: HABTM, yes it's a bit puzzling it's set up this way. Historically I've done my join tables defined as models themselves similar to how you've described, and created their migrations accordingly. I didn't even know there was a "Rails" way of creating a join_table migration until I poked through the migration files.

duck monster
Dec 15, 2004

Partycat posted:

I have been working on developing my internal toolset in ruby and rails, and have been slowly improving with my techniques, built my own internal gem for some modules, etc

Is the general opinion on this that I should be doing this in python instead at this point? Is Ruby falling apart into decay?
Unpopular opinion, but yes. Ditto with Node JS. The jobs have been drying up as companies move across to python, and a LOT of pretty important libraries seem abandoned now.

quote:

Python immediately turned me off by being column/space dependent giving me COBOL flashbacks, was really hoping not to have to deal with that poo poo or line terminators ever again.

Im an ex-COBOL coder too. So I feel you on this one. But overcome it. Ive been using python since the 90s and its a genuinely great little language. Its got its downsides, I wish they'd adapt rubys closures, but its a mature, comfortable language wth some genuinely great libraries. Well unless the hipsters get bored and leave a trail of library corpses as they shfit to, i dunno , loving Golang or something. And while Rails is pretty fun to work with, Django's ORM blows pretty much the entire field of its competitors out the water. Class based views are a clusterfuck though.Rail's Spec is peerless though. Best testing system ive ever worked with

duck monster fucked around with this message at 13:45 on Oct 4, 2019

kayakyakr
Feb 16, 2004

Kayak is true

duck monster posted:

Unpopular opinion, but yes. Ditto with Node JS. The jobs have been drying up as companies move across to python, and a LOT of pretty important libraries seem abandoned now.

I disagree. I think Rails is holding steady as a fantastic low-risk language for startups and I found plenty of jobs out there for senior devs. It's biggest competitor is not python, but instead NodeJS which is still getting a lot of new startup work.

I feel that Python is tending to carnivorize more and more of Java and Microsoft's markets. Depending on which metrics you track, Ruby's been up or at least holding steady YoY. There are some old libraries that seem abandoned, but I prefer to think of them as "mature" :)

xtal
Jan 9, 2011

by Fluffdaddy
Rails is as good as ever, it just moved from "new and trendy" to "old and reliable"

duck monster
Dec 15, 2004

edit: whoops identity leak

duck monster fucked around with this message at 16:01 on Oct 10, 2019

Peristalsis
Apr 5, 2004
Move along.
I have a Capybara test that passes locally, but fails intermittently (almost always at the moment) on our CI.

The test clicks on a link to open a menu, then clicks on a link on the menu. That menu link isn't visible, and I don't know why. Does anyone have any suggestions of something I could try?

Here's roughly how the test works:
code:
scenario 'test link' do
  login_as(admin_user)
  visit('/')
  click_link('Admin')
  expect(page).to have_link('Versions', wait: 10)  # Delay to let screen resolve - Test fails here on CI
  click_link('Versions')
  expect(page).to have_current_path(versions_path)
end
The 'Versions' link isn't found on CI. I don't think I have access to the CI server, certainly I can't log in and use a debugger to explore what's going on. Maybe I could save off a screen shot, but I'm not sure if that would work or how I would retrieve it.

I can comment out/delete this test - it's just verifying that a menu link works - but I'd like to fix it if I can.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
What drivers do you use to run capybara? Is resolution configured the same on CI and locally?

It is possible that the browser resolution is different on CI and the button is hidden at that resolution. However I would expect the test to fail every time on CI in that case.

Also are you using ajax to load the button?Might be an issue there too.

Pollyanna
Mar 5, 2005

Milk's on them.


We had an issue once where resizing the window during a test caused it to fail intermittently in CI. That was fun.

duck monster
Dec 15, 2004

Pollyanna posted:

We had an issue once where resizing the window during a test caused it to fail intermittently in CI. That was fun.

We had to abandon AWS' device farm because randomly it wouldnt open the app, and instead just click on random poo poo. Actually it almost never did. loving useless

Edgar Allan Pwned
Apr 4, 2011

Quoth the Raven "I love the power glove. It's so bad..."
so im working on a coding practice, using an api for a random name and another api for a random joke. im supposed to be able to create an api that generates this new joke on create. it will be tested by using curl.

so i gotten all of the parts working, creating the new joke, gettinn CRUD to work for my api. the only thing is, im trying to get my method (for creating the new joke) to run when i create a new instance of the model. it is not working.

is running methods in the create method common? is there a different way i should be thinking about this?

should i be having the user run the method on create manually? this seems wrong but im not finding a ton on google for running a method for params on create.

kayakyakr
Feb 16, 2004

Kayak is true

Edgar Allan Pwned posted:

so im working on a coding practice, using an api for a random name and another api for a random joke. im supposed to be able to create an api that generates this new joke on create. it will be tested by using curl.

so i gotten all of the parts working, creating the new joke, gettinn CRUD to work for my api. the only thing is, im trying to get my method (for creating the new joke) to run when i create a new instance of the model. it is not working.

is running methods in the create method common? is there a different way i should be thinking about this?

should i be having the user run the method on create manually? this seems wrong but im not finding a ton on google for running a method for params on create.

You can either use a service pattern or a before_create callback. You can also make a fat controller because WGAF and call out to the API there. Depends on what all is involved in generating a new joke. Is it calling a separate api? Is it calling a machine learning algorithm? Asking a contractor overseas?

Tea Bone
Feb 18, 2011

I'm going for gasps.
I have two models with a relationship similar to this:

code:
class Card
	belongs_to :suit
end

class Suit
	has_one :ace, ->{where(value: ‘ace')}, class_name: Card
	has_one :king, ->{where(value:’king’)}, class_name:Card
end
a the moment if I run:

code:
card = Card.new
suit = Suit.new
suit.ace = c
suit.save
The suit and card both save, but the value on the card isn’t set to 'ace'. Is there a call back I can add to the has_one relationships which will automatically scope any cards when they’re added? I can over ride the ace= and king= methods in the Suit model but that seems messy.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
Is there a reason you can't do

code:
suit = Suit.new
card = suit.build_ace

kayakyakr
Feb 16, 2004

Kayak is true
I'd probably build it where

code:
class Suit
  has_many :cards
end

class Suit
  belongs_to :suit

  validates :uniqueness, :value, scope: [:suit]

  scope :ace, ->{where(value: 'ace').limit(1)}
end
Then you can find specific cards via suit.cards.ace.first

Tea Bone
Feb 18, 2011

I'm going for gasps.

The Milkman posted:

Is there a reason you can't do

code:
suit = Suit.new
card = suit.build_ace


The Milkman posted:

Is there a reason you can't do

code:
suit = Suit.new
card = suit.build_ace

Thanks guys. I ended up flipping the relationship (so that suit belonged to card) as it made more sense for my use case and that ended up solving the issue.

kayakyakr
Feb 16, 2004

Kayak is true

Tea Bone posted:

Thanks guys. I ended up flipping the relationship (so that suit belonged to card) as it made more sense for my use case and that ended up solving the issue.

So you have... 4 suits per card and 13 suits per deck? Interesting setup indeed...

xtal
Jan 9, 2011

by Fluffdaddy
I'm almost certain that the problem is that you don't have `inverse_of` in the relationship definition, this is common gotcha, but I didn't test it

This (pretty old) article says that you need inverse_of when specifying conditions/scopes

xtal fucked around with this message at 23:24 on Jan 29, 2020

Jaded Burnout
Jul 10, 2004


I've been working with Rails for a very long time, and I have a new side project I'd like to do that's very data input heavy, and I absolutely cannot face setting up all the controllers and such. Is there a nicer way to do it than either grinding through it or using the scaffolding generators? Anything nice and dynamic that doesn't immediately fall apart?

I'm just so tired.

kayakyakr
Feb 16, 2004

Kayak is true

Jaded Burnout posted:

I've been working with Rails for a very long time, and I have a new side project I'd like to do that's very data input heavy, and I absolutely cannot face setting up all the controllers and such. Is there a nicer way to do it than either grinding through it or using the scaffolding generators? Anything nice and dynamic that doesn't immediately fall apart?

I'm just so tired.

I mean, are you looking for admin interfaces like rails-admin? Or are you looking for, say a CMS backend like Contentful or Kentico?

Or, if you need to roll something yourself, this looks like a fun way to get a quick data server going and being GraphQL it's decidedly NOT rails: https://evilmartians.com/chronicles/graphql-on-rails-1-from-zero-to-the-first-query

Jaded Burnout
Jul 10, 2004


kayakyakr posted:

Or, if you need to roll something yourself, this looks like a fun way to get a quick data server going and being GraphQL it's decidedly NOT rails: https://evilmartians.com/chronicles/graphql-on-rails-1-from-zero-to-the-first-query

I've used this for a client project and it's just about the opposite of what I'm after since yes you only need one controller but you need to create equivalent queries and mutations for everything plus a whole JS frontend.

kayakyakr posted:

I mean, are you looking for admin interfaces like rails-admin?

This, however, is exactly the sort of thing I was looking for. Looks like there's rails-admin, activeadmin, and administrate available. I'll probs try out administrate. Thanks!

GeorgieMordor
Jan 23, 2015
Has anyone upgraded to Xcode 11.3.1 recently and -- no surprise -- had it bork their Rails environment? I'm working on 2 separate Rails 6 apps right now, and one symptom in both of them is my console seemingly failing on proper output with ActiveRecord. I am given zero errors in any respect -- have absolutely no idea what could be causing this.

Both apps run fine in both dev and all live environments (stag, prod, etc) on their respective servers.

Here's an example:

code:
irb(main):001:0> @v = Vault.new(name: "Forte Knoxxe")
irb(main):002:0> @v.save
   (0.3ms)  BEGIN
  Vault Create (6.1ms)  INSERT INTO "vaults" ("name", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["name", "Forte Knoxxe"], ["created_at", "2020-03-20 17:51:59.971112"], ["updated_at", "2020-03-20 17:51:59.971112"]]
   (5.2ms)  COMMIT
irb(main):003:0> @v2 = Vault.last
  Vault Load (0.7ms)  SELECT "vaults".* FROM "vaults" ORDER BY "vaults"."id" DESC LIMIT $1  [["LIMIT", 1]]
irb(main):004:0> @v2.inspect
irb(main):005:0> Vault.count
   (1.0ms)  SELECT COUNT(*) FROM "vaults"
irb(main):006:0>
Things I've tried to rectify so far:
- Re-installing readline
- Re-installing local Ruby version
- Re-installing Rails gem

Suspicion is of course something isn't getting pointed to properly, but there is absolutely no errors indicated what that might be anywhere.

EDIT: Some further insight. Looks like behind the scenes everything is working, just not outputting as expected. For example, adding a puts declaration outputs what the console did historically / normally. Still no idea what is going on or why.

Example:

code:
irb(main):001:0> puts Vault.count
   (0.7ms)  SELECT COUNT(*) FROM "vaults"
3
irb(main):002:0> puts @v = Vault.first
  Vault Load (0.3ms)  SELECT "vaults".* FROM "vaults" ORDER BY "vaults"."id" ASC LIMIT $1  [["LIMIT", 1]]
#<Vault:0x00007f85014bbbe8>
irb(main):003:0> @v
irb(main):004:0> @v.inspect
irb(main):005:0> puts @v.inspect
#<Vault id: 1, name: "Stashe", created_at: "2020-03-19 18:18:37", updated_at: "2020-03-19 18:18:37">
irb(main):006:0>
EDIT: Found this whole problem was being caused by either an overwritten or a newly added .irbrc file. Echo was explicitly set to off -- it was the only declaration in that file. I've never messed with that file in the past at all or had to, so didn't think to check it.

GeorgieMordor fucked around with this message at 14:11 on Mar 23, 2020

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
Does anybody have any recommendations for resources I can use to learn Rails v5.1+ ?

All the popular tutorials out there seem to be with older versions (from 2011 -> 2017 commonly) which have some pretty noticeable differences to what the latest Rails documentation offers (which seems pretty light on details, somehow??) and I'm not sure what differences are significant and which aren't.

I'm doing a test run on building a project and working on it, and I'm running into all sorts of hosed up issues with model objects not being passed to the form and so forth, and I have no idea what I've done wrong or why. But when comparing to github repos and written/video tutorials and the base documentation, I see a whole bunch of different ways to do things and it's not really clear why there are differences or how important they are.

For example:

railscasts.com - latest episode was 2013, 7 years ago
gorails.com - recent episodes seem to be aimed at very specific, more advanced topics, and the base/intro episodes are all from 2014 or so
driftingruby.com - seems to be aimed at more advanced topics
railstutorial.org - was published in 2010, no mention if it's been updated since then

and youtube most of the videos seem to be 2017 at the latest and from people who are learning it themselves, so they dont have good explanations of why theyre doing what theyre doing

Sulla Faex fucked around with this message at 09:42 on Mar 28, 2020

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India

Sulla Faex posted:

railstutorial.org - was published in 2010, no mention if it's been updated since then
https://www.railstutorial.org/book

It says in the first sentence below the title that it was updated for Rails 6. Also https://guides.rubyonrails.org/ these are up to date.

Jaded Burnout
Jul 10, 2004


The two biggest sea changes in Rails have been 1 -> 2 and 2 -> 3, beyond that it's a much more incremental change, so as long as you're taking the broad concepts from your reading and not latching on letter by letter then you'll find value in anything written for 3+. https://api.rubyonrails.org is my go-to resource for hyper specifics, and the guides are a decent introduction though I find them in a muddy middle ground between doc and guide.

Nybble
Jun 28, 2008

praise chuck, raise heck
PragProg’s Rails 6 book has been a nice re-introduction for me, since my professional experience was mostly around Rails 4 and I’m hopping back in. https://pragprog.com/book/rails6/agile-web-development-with-rails-6

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
Basically, from Rails 4 and on, from an outward facing perspective, it's been just adding new core libraries to tackle various areas: ActiveJob (background jobs), ActiveStorage (file uploads), ActionText (rich text editing), ActionMailbox (receiving email) and probably others I'm forgetting. Any of the concepts from oldish material will still largely still apply, maybe some minor syntax tweaks. There are some big changes like System Tests (browser testing) you'll want to use, and others you may want/need to deal with like Webpacker.

The PragProg Rails book is up-to-date and excellent. I also recommend whatever the latest edition of Rails Test Prescriptions by Noel Rappin is.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
Thank you for the replies! I think my issue is that the syntax keeps changing between the material I was using to learn it, and whenever I tried to follow one example precisely, it wouldn't work on the MVC level without significant experimentation and changing, and it was getting really hard to track why people were doing anything or why one thing was working and one wasn't. I think I'll get the PragProg book and start from scratch with that

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
I'm running into a problem with creating conditional unique validations in the model/db. I have three relevant columns in a model, "user_id", "city_id", and "active". I'm trying to create two validation checks:

1. each user_id and city_id pair must be unique
2. each user can have only ONE row where active=1

1 is working fine, but 2 I can't get to work.

My model file:

code:
class CityPlayer < ApplicationRecord
  belongs_to :city
  belongs_to :user

  validates_uniqueness_of :city_id, :scope => :user_id
  validates_uniqueness_of :active, :scope => :user_id, if: Proc.new {|city_player| city_player.active?}

end
and the table definition from my generated db/schema.rb file:

code:
  create_table "city_players", force: :cascade do |t|
    t.integer "city_id"
    t.integer "user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.boolean "active", default: false
    t.index ["active", "user_id"], name: "index_city_players_on_active_and_user_id", unique: true
    t.index ["city_id"], name: "index_city_players_on_city_id"
    t.index ["user_id"], name: "index_city_players_on_user_id"
  end
I can't tell but it seems like the DB has a less-nuanced version of the conditional uniqueness validation than the rails model has.

Because the error I consistently get when trying to create a new city_player is:

quote:

SQLite3::ConstraintException: UNIQUE constraint failed: city_players.active, city_players.user_id: INSERT INTO "city_players" ("city_id", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?)

Which makes me think the DB is just validating on "is user_id and active the same? (regardless of the value of active)"

Incidentally, I'm using rails_admin as an easy DB workbench and nothing I can do is able to get it to show all columns in city_players, i.e. "active" doesn't show at all, despite it showing in the actual DB via dbconsole.

Sulla Faex fucked around with this message at 15:55 on Jun 9, 2020

Adbot
ADBOT LOVES YOU

Jaded Burnout
Jul 10, 2004


OK, so first off `if: Proc.new {|city_player| city_player.active?}` can be replaced with `if: :active?`. Secondly, it feels like this is a good candidate for a custom validation, rather than trying to push the envelope of the uniqueness validation. Thirdly, yes you're correct that unique indexes DB-side are a simpler logic. If you want something more complex DB-side then you need something like a "check constraint", which may or may not be available in sqlite.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply