#RubyOnRails - 26 July 2018
« Back 1 day Forward 1 day »
[03:16:46] ian_strascina: I have a column defined as :string in the migration. However, when I load a FactoryBot factory, somehow the string value is getting turned into an integer in the DB. Any ideas why that would be happening?
[03:18:02] ian_strascina: Postgres - says "Character Varying". Other string columns that are working correctly say the same.
[03:18:46] ian_strascina: Model.columns shows @sql_type_metadata= ... @sql_type="character varying", @type=:string>
[03:25:40] ian_strascina: Here it is: https://gist.github.com/istrasci/bed25d8d6c47e6189ab30a230daf0807
[03:28:59] ian_strascina: Yes, DB show "character varying", and the RateMatrixFactor.columns shows this too.
[03:31:17] sevenseacat: can you show the actual SQL that gets generated when inserting the factory record? for some reason Rails thinks you have an integer field
[03:33:44] osp2: oh wait I guess I misunderstood, the csv is the output? where code is getting transformed to 0?
[03:35:56] osp2: https://gist.github.com/istrasci/bed25d8d6c47e6189ab30a230daf0807/revisions#diff-4a10a888955d39c4fcf489ac6f6b4188
[03:36:11] osp2: oops sorry wrong link: https://gist.github.com/istrasci/bed25d8d6c47e6189ab30a230daf0807#file-rails_console_output-txt-L28
[03:37:30] ian_strascina: So somewhere, the string value ("term") is getting ditched and replaced with 0.
[03:39:29] ian_strascina: Just paste error. There were several other factories that I deleted. Must've clipped that end too.
[03:42:53] ian_strascina: Additional info: The "code" column _used_ to be a string (set up by another developer). I wrote a migration to change the column type to string.
[03:43:26] ian_strascina: Otherwise, I have several other tables doing the exact same thing with factories, and they're all working fine as expected.
[03:44:12] ian_strascina: "enum code: [:term, :amount, :credit_score, :age_collateral]" was buried in there.
[09:00:07] tomaz_b: i am not really Rails user, but I have to deploy one to AWS, with Docker behind Nginx. I have a really strange behaviour. In can see really slow behaviur. Almost similar to this https://github.com/docker/compose/issues/356
[09:01:33] tomaz_b: some are writing that it might be like a reverse DNS setup somewere... i tried few of the settings... but nothing really works for me.
[10:40:42] chridal: Is there a way to generate a 'generic' path in Rails? Today I'd do post_path(@post), but is there a way of doing something like path_to(SomeObj) and then have that resolve to `post_path` if I gave it a Post obj?
[11:26:03] mojtaba: Hello, I was following a tutorial to create a migration, but I had a typo. I fixed the typo an ran again the migration command. But it says ruby has aborted the operation. (because part of the migration has been done.) do you know how can I fix this issue?
[11:35:32] tbuehlmann: the migration should've completed the first time. I'd roll that migration (including the typo) back, fix the typo and migrate again
[16:07:03] syndikate: tycoon177, nope. I understand that difference. I had a route like this `resources :probation`. Here, I didn't provide a plural name and things were all quite messed up
[16:07:33] syndikate: I thought it doesn't matter what the resource name's state is but `resource` or `resources` mattered
[16:08:49] tycoon177: i'm fairly sure that `resources :probations` would be required here. AFAIK, `resources` is always expecting a plural name
[16:39:27] HeyoRockbreaker: Oh shoot. Any idea why Rails isn't allowing me to use standard generators?
[16:40:17] HeyoRockbreaker: https://gist.github.com/HeyoRockbreaker/fe52ccbe9ddafe9667833c184c7c7f80
[17:54:52] mlt-: Radar: Thanks for the feedback! The intent is to be generic tool for SQL export. There is no particular model, lots of dynamic SQL.
[17:57:02] mlt-: I just don't want to get low on memory on exporting let's say a few millions of rows
[18:54:49] syndikate: tycoon177, okay. Although I thought even if I don't give plural names, only the naming schema would be screwed, apparently the whole path is changed
[18:55:33] dopie: Hey guys I have a polymorphic Image and I want to delete it but since its polymorphic I am trying to deelte it and re-render the page it was deeleted on I tried :back but it goes back a page and im using rails 5
[18:58:25] tycoon177: syndikate: why wouldn't it change the paths? it's a completely different resource :)
[19:05:23] mlt-: dopie: I'm not sure how "polymorphic" is relevant here. But what about rendering JS asking Turbolinks to visit and replace # thus re-rendering your page?
[20:50:21] tycoon177: is there a way to create a has_many association on multiple foreign keys? right now, i have a method named after the association that just calls to the other model directly, but this stops me from using the association in `includes` or `joins` and has been causing n+1 queries out that wazoo
[21:15:05] desnudopenguino: tycoon177: you mean something like this? https://stackoverflow.com/questions/307581/rails-model-has-many-with-multiple-foreign-keys
[21:17:17] tycoon177: desnudopenguino: no, sorry, i didn't explain it well. The two tables should be connected via 3 of their columns. the rows only match if all 3 values match. it's a strange, strange setup, i know, but it was well in place before i got here :p
[21:17:49] tycoon177: desnudopenguino: i think i'll end up just joining on a different table and then use #select or #keep_if on the ruby end of things
[21:22:00] mlt-: tycoon177: are you looking for this https://github.com/composite-primary-keys/composite_primary_keys ?
[21:24:59] tycoon177: mlt-: when you say raw sql, how do you manage this in rails? can you set the join syntax when setting a has_many or a belongs_to? i'd be happy to do that, but i don't think i'll use that gem
[21:25:18] desnudopenguino: raw sql is usually how i handle those things, until i figure out a more "railsy" way to do it
[21:26:19] tycoon177: how would i be able to do this join (or includes) with raw sql if wanted to use the model in rails too?
[21:27:27] tycoon177: it's fine, i'll just join on another table that's already in the query and then filter my results with #select
[21:28:24] mlt-: tycoon177: if you use only a handful of scenarios where you do such join, just define a method for a final stuff you'd want. Apparently you can't use raw SQL if you expect to have AR relation to work with later
[21:29:22] tycoon177: thanks for taking another look! i was hoping that i was overlooking something in the docs, but this is a very odd thing to have to do, i'll admit
[21:29:56] tycoon177: i can very easily think of a better schema that would've fixed this, but technical debt is preventing such a migration
[21:31:25] mordof: i've got a little bit of a chicken and egg situation happening. i've got a model with a string on it - which validates the presence of that string. but the first time it's saved, that string will be empty and it should generate a new string. i was using before_validation on :create, but that's happening even if i just call .validate on the record
[21:31:26] mlt-: I mean you can always have a surrogate key, but it doesn't always mean table is not normalized
[21:31:58] mordof: is there any spot where i can have a callback on a model that happens before validation, but only from a call where it's trying to save it for the first time to the database? using rails 5
[21:36:04] mordof: ah, mb.. validates presence and unique* sorry. think bitly with generating a url for something. that's kind of what i'm trying to do
[21:36:38] mordof: i want to create a new record, and give it a path, but that path needs to be unique.. and only generated when a record is going to be committed to the database
[21:38:42] mordof: mlt-: i'll keep it in mind.. right now that doesn't quite fit what's in my head about how to tackle this... but i'm potentially just locking myself in a corner using both a generator and a validator
[21:42:49] desnudopenguino: there are a few thoughts i have, is the record going to be written once and that's it, or is it updatable? if it is a write once thing, then you could use a before_validate to create and check the unique string
[21:43:30] mordof: that field should only be written once, yes. other details can be updated but i don't think that's relevant.
[21:43:44] desnudopenguino: if it is updatable, you could just have some logit to check if the value is set in the before_validate
[21:44:31] mordof: ah - so instead of having a normal validator for presence and unique, just have the before_validate do both and ensure it makes sense
[21:46:04] mordof: hmm yeah if i'm doing that.. then it makes sense to put it in a before_create so that it only happens in that step then
[21:46:32] mordof: before_validation isn't scoping to the create even though the docs suggest it should, so it's problematic to try and use that
[21:51:06] desnudopenguino: i think i've run into a similar scenario, but can't remember exactly. things in the callbacks felt a bit "off"