« Back to channel list

#RubyOnRails - 20 December 2017

« Back 1 day Forward 1 day »
[00:00:06] thortron: has joined #RubyOnRails
[00:03:29] pharma_joe: has joined #RubyOnRails
[00:03:35] amperry: tfitts: going to rename the column even though it isn't new. Git save us all.
[00:03:59] tjbp: has joined #RubyOnRails
[00:05:10] tjbp: has joined #RubyOnRails
[00:10:55] alfiemax: has joined #RubyOnRails
[00:13:06] my123: has joined #RubyOnRails
[00:18:54] amperry: tfitts: just FYI, renaming the column did it. Thanks.
[00:19:04] tfitts: no problem
[00:26:25] pharma_joe: has joined #RubyOnRails
[00:30:29] sevenseacat: has joined #RubyOnRails
[00:32:07] ur5us: has joined #RubyOnRails
[00:35:55] keegnotrub: has joined #RubyOnRails
[00:36:18] moei: has joined #RubyOnRails
[00:38:06] alexertech: has joined #RubyOnRails
[00:44:20] tfitts: I'm wondering if anyone has done STI without a type column? I'd like to just use some data from the model as they did here https://www.salsify.com/blog/engineering/bye-bye-sti-hello-discriminable-model but things have changed since then.
[00:57:11] Jameser: has joined #RubyOnRails
[00:57:31] quazimodo: has joined #RubyOnRails
[01:03:05] Mvfc: has joined #RubyOnRails
[01:07:39] hahuang65: has joined #RubyOnRails
[01:12:45] ur5us: has joined #RubyOnRails
[01:13:34] Mvfc: has joined #RubyOnRails
[01:16:40] Mvfc: has joined #RubyOnRails
[01:19:08] cagomez: has joined #RubyOnRails
[01:30:36] Mvfc: has joined #RubyOnRails
[01:48:22] orbyt_: has joined #RubyOnRails
[02:06:22] Cache_Money: has joined #RubyOnRails
[02:10:42] alfiemax: has joined #RubyOnRails
[02:31:14] jnollette: has joined #RubyOnRails
[02:47:18] borodin: has joined #RubyOnRails
[02:51:34] mtkd: has joined #RubyOnRails
[03:06:10] orbyt_: has joined #RubyOnRails
[03:06:13] alfiemax: has joined #RubyOnRails
[03:08:56] hahuang65: has joined #RubyOnRails
[03:18:20] alfiemax: has joined #RubyOnRails
[03:23:19] MrCrackPotBuilde: has joined #RubyOnRails
[03:27:53] Or1on: has joined #RubyOnRails
[03:39:46] tcopeland1: has joined #RubyOnRails
[03:43:08] alexertech: has joined #RubyOnRails
[03:46:39] ephemer0l: has joined #RubyOnRails
[03:53:25] alfiemax: has joined #RubyOnRails
[03:54:15] tcopeland1: has joined #RubyOnRails
[04:01:45] arpu: has joined #RubyOnRails
[04:15:00] srinidhi: has joined #RubyOnRails
[04:27:25] nso95: has joined #RubyOnRails
[04:38:43] icharlie: has joined #RubyOnRails
[05:01:08] mtkd: has joined #RubyOnRails
[05:08:01] r0ph: has joined #RubyOnRails
[05:09:45] hahuang65: has joined #RubyOnRails
[05:31:37] srinidhi: has joined #RubyOnRails
[05:36:32] armyriad: has joined #RubyOnRails
[05:39:56] iamarun: has joined #RubyOnRails
[05:41:11] dionysus69: has joined #RubyOnRails
[05:43:33] duderono_: has joined #RubyOnRails
[05:44:52] sevenseacat: has joined #RubyOnRails
[05:48:37] xpl0iter: has joined #RubyOnRails
[05:55:45] ephemer0l: has joined #RubyOnRails
[06:11:20] swati_27: has joined #RubyOnRails
[06:20:46] s2013: has joined #RubyOnRails
[06:28:34] reber: has joined #RubyOnRails
[06:34:22] sevenseacat: has joined #RubyOnRails
[06:55:41] conta: has joined #RubyOnRails
[06:58:37] za1b1tsu: has joined #RubyOnRails
[06:59:36] rwb-averon: has joined #RubyOnRails
[06:59:59] rwb-averon: if validation fails are before_save callbacks called?
[07:01:07] za1b1tsu: Hello, regarding FactoryBot is it possible to create different objects with the same create method? Like https://gist.github.com/anonymous/f1b7dab11cccdc708f5b6cbb8b1e8a26 I tried different combinations of [] {} but no success
[07:01:59] sevenseacat: za1b1tsu: no. use separate create calls.
[07:02:28] za1b1tsu: sevenseacat not even with create_list?
[07:02:45] sevenseacat: thats not what your example did.
[07:03:07] sevenseacat: you can't instantiate different factories with create_list.
[07:05:08] za1b1tsu: sevenseacat, thanks man, I'm trying to adhere to DRY principle, is this good/clean/ruby-like code ? https://gist.github.com/anonymous/31fa46ac780263b77e9276810718394f
[07:05:28] sevenseacat: I wouldnt write it.
[07:05:37] sevenseacat: why a loop over two calls to create?
[07:05:55] za1b1tsu: Oh, I'm going to do at least 4
[07:06:06] za1b1tsu: multiple traits
[07:06:12] sevenseacat: okay, why a loop over four calls to create?
[07:06:43] za1b1tsu: so I dont repeat Factory.create, efficiency?
[07:07:00] sevenseacat: DRY is about concepts and logic, not lines of code
[07:08:28] sevenseacat: do you need to refer to the generated data? you're not assigning it anywhere
[07:09:14] za1b1tsu: Im using it in seed
[07:10:33] za1b1tsu: I know it's not good practice :)
[07:10:37] hahuang65: has joined #RubyOnRails
[07:10:47] sevenseacat: >is this good/clean/ruby-like code
[07:10:58] sevenseacat: guess you just answered your own question eh
[07:13:39] za1b1tsu: The factories I'm making are dependent on the existence of another activerecord. Is it good practice to create a factory for the parent class first and in an after hook generate the child factories?
[07:14:17] za1b1tsu: So I just create the single parent and I will have the children as well?
[07:47:32] apeiros: has joined #RubyOnRails
[08:05:28] mtkd: has joined #RubyOnRails
[08:20:50] fugee: has joined #RubyOnRails
[08:21:03] fugee: how do i drop ship with spree
[08:26:33] pikislabis: has joined #RubyOnRails
[08:28:50] xpl0iter: has joined #RubyOnRails
[08:37:39] pwnd_nsfw: Wassup mices !?!
[08:38:09] mices: pwnd_nsfw: hi
[08:38:10] pwnd_nsfw: I think to drop ship with any application rm -rf
[08:42:22] ferr: has joined #RubyOnRails
[08:51:47] moei: has joined #RubyOnRails
[08:58:59] gauravgoyal: has joined #RubyOnRails
[09:05:31] Dimik: has joined #RubyOnRails
[09:10:42] srinidhi: has joined #RubyOnRails
[09:11:40] hahuang65: has joined #RubyOnRails
[09:17:25] KeyJoo: has joined #RubyOnRails
[09:18:58] cschneid_: has joined #RubyOnRails
[09:20:45] ur5us: has joined #RubyOnRails
[09:20:47] sevenseacat: has joined #RubyOnRails
[09:27:45] marr: has joined #RubyOnRails
[09:40:54] coderxin: has joined #RubyOnRails
[09:42:14] arBmind: has joined #RubyOnRails
[09:50:54] kapil___: has joined #RubyOnRails
[09:51:28] bronson_: has joined #RubyOnRails
[09:58:59] ferr: has left #RubyOnRails: ("WeeChat 2.0")
[10:01:48] cabotto: has joined #RubyOnRails
[10:07:57] ams__: has joined #RubyOnRails
[10:09:32] Cavallari: has joined #RubyOnRails
[10:15:12] sevenseacat: has joined #RubyOnRails
[10:26:35] alfiemax: has joined #RubyOnRails
[10:34:29] arBmind: has joined #RubyOnRails
[10:44:09] Jameser: has joined #RubyOnRails
[10:52:31] workmad3: has joined #RubyOnRails
[10:53:09] phon: has joined #RubyOnRails
[10:54:31] cabotto: has joined #RubyOnRails
[11:05:54] ur5us: has joined #RubyOnRails
[11:07:54] arBmind: has joined #RubyOnRails
[11:12:31] hahuang65: has joined #RubyOnRails
[11:16:02] cabotto: has joined #RubyOnRails
[11:51:32] quazimodo: has joined #RubyOnRails
[11:59:53] dionysus69: has joined #RubyOnRails
[12:00:37] uksio: has joined #RubyOnRails
[12:00:59] conta: has joined #RubyOnRails
[12:04:08] cabotto: has joined #RubyOnRails
[12:09:56] za1b1tsu: has joined #RubyOnRails
[12:17:09] conta: has joined #RubyOnRails
[12:17:26] pikislabis: has joined #RubyOnRails
[12:18:25] za1b1tsu: Hello, I have a model called rating, that belongs to many subjects and belongs to many sessions. I don't know what namespaces should I use in routes. No namespace, maybe? What is the criteria to choose a namespace in this situation?
[12:18:50] _ritchie_: has joined #RubyOnRails
[12:22:52] za1b1tsu: sessions and subjects dont have a direct association, a client has orders that have a session and the clients has many subjects
[12:24:27] DaniG2k: has joined #RubyOnRails
[12:24:38] DaniG2k: hello all, I'm trying to write a spec that runs some javascript on my page (more specifically select2)
[12:25:02] DaniG2k: the problem I'm having is that select2 makes an ajax request to an API endpoint in my app
[12:25:43] DaniG2k: when I take a screenshot of the page with poltergeist though, I'm seeing that select2 says "The results could not be loaded"
[12:26:36] DaniG2k: so I think there might be several issues here: 1) the api call isn't working in test env. 2) the ajax call isn't working in test env
[12:27:03] DaniG2k: the ajax call is relative so it shouldn't make a difference
[12:27:07] DaniG2k: url: '/api/admin/s/users'
[12:28:22] DaniG2k: not sure what else the problem could be
[12:29:18] coderxin: has joined #RubyOnRails
[12:37:13] fschuindt: has joined #RubyOnRails
[12:41:00] DrYockel: has joined #RubyOnRails
[12:43:19] waseem_: has joined #RubyOnRails
[12:50:29] DaniG2k: I've outlined the question in more detail here: https://stackoverflow.com/questions/47906397/testing-select2-with-rspec-poltergeist
[12:51:47] sevenseacat: thats a totally different issue than you just described, which are you trying to solve?
[12:53:16] sevenseacat: https://github.com/bblimke/webmock/issues/284 will fix the __identify__ issue
[12:53:47] tcopeland: has joined #RubyOnRails
[12:54:01] morfin60: has joined #RubyOnRails
[12:54:23] _ritchie_: has joined #RubyOnRails
[12:54:26] morfin60: does Rails autoload classes from app/ if that's in gem?
[12:57:06] fschuindt: morfin60: the class belongs to a gem or it's inside a file into app/?
[12:58:28] fschuindt: if it's inside a default Rails dir like app/models it will be autoloaded. if you want to create a new folder for it, you may specify Rails config to load that path
[12:58:45] sevenseacat: everything in app/ is autoloaded.
[12:59:17] morfin60: class belongs to gem but in gemdir/app
[13:06:22] ur5us: has joined #RubyOnRails
[13:08:14] xpl0iter: has joined #RubyOnRails
[13:08:26] Ergo: has joined #RubyOnRails
[13:13:21] hahuang65: has joined #RubyOnRails
[13:19:51] morfin60: seems like answer is no
[13:20:18] cschneid_: has joined #RubyOnRails
[13:26:00] DaniG2k: has joined #RubyOnRails
[13:28:46] jnollette: has joined #RubyOnRails
[13:29:06] Jameser: has joined #RubyOnRails
[13:30:26] quazimodo: has joined #RubyOnRails
[13:30:32] noob_on_rails: has joined #RubyOnRails
[13:32:01] jnollette: has joined #RubyOnRails
[13:32:38] noob_on_rails: hey all , what's the best place to declare flat classes in Rails?
[13:44:54] waseem_: noob_on_rails: What is a flat class?
[13:45:30] noob_on_rails: class Foo; end
[13:45:53] noob_on_rails: i mean , not inheriting from anything rails related
[13:46:05] noob_on_rails: just there to be instantiated , refactor functionality
[13:46:37] waseem_: noob_on_rails: Probably lib/.
[13:46:57] morfin60: if it's not something like service/helper etc then i think so
[13:48:18] alfiemax: has joined #RubyOnRails
[13:48:43] noob_on_rails: ok thanks guys :D
[13:49:05] mtkd: has joined #RubyOnRails
[13:52:37] morfin60: can i somehow autoload models from external gem?
[13:53:29] dachinat: has joined #RubyOnRails
[13:53:45] noob_on_rails: also as another question , is there a way to make a REST request to my own server? but whithout going over the web
[13:54:45] waseem_: noob_on_rails: Why do you want to make a request to your own server?
[13:54:51] dachinat: I had this issue and I thought it was because of bad database build, but I faced it again. When I'm updating a record that accepts nested attributes and an update is invalid I'm getting wrong @foo.bars.first.id in unsuccessful update block. Do you know why this happens, any way I can get around this issue?
[13:55:11] noob_on_rails: waseem_: i have a functionality , which at the moment uses external API's and mashes the respose
[13:55:25] noob_on_rails: now i want to pass throught the same feature , internal payloads
[13:56:12] noob_on_rails: this as you'd imagine include validations and standard procedures
[13:56:37] noob_on_rails: so , if i had a valid way to refer to rails internally in the same fashion it'd be cool ..
[13:56:52] dminuoso: noob_on_rails: You cant sensibly.
[13:57:02] dminuoso: And you shouldn't.
[13:57:14] alfiemax: has joined #RubyOnRails
[13:58:12] noob_on_rails: dminuoso: im trying to think of other ways. i do agree tho
[13:58:21] waseem_: noob_on_rails: Sounds like you need to refactor out the functionality in question in another object and use it at different places.
[13:58:36] dminuoso: noob_on_rails: The way to share code in ruby is...
[13:58:38] dminuoso: hold yourself...
[13:59:04] dminuoso: (Whether you include them or use methods on a modules singleton class is up to you)
[13:59:57] noob_on_rails: ok ill have to look into modules and see if they fit
[14:00:10] noob_on_rails: thanks dminuoso :)
[14:01:06] noob_on_rails: waseem_: yea , i think one way or another , that's what ill end up doing. thank you too :)
[14:01:47] waseem_: morfin60: Which gem is it? This functionality should be provided by the gem itself.
[14:02:57] waseem_: morfin60: When you're doing `gem 'foo'` in your Gemfile you're telling bundler to require it when you start your rails server/console with `bundle exec rails s/c`.
[14:04:14] dachinat: https://paste.ofcode.org/tPHnLrq5EW2cP2NegcwGNh These log outputs differ for some reason... Haven't you faced such issue?
[14:06:18] Jameser: has joined #RubyOnRails
[14:06:49] dachinat: If I type @foo.reload before second logging then value is correct, but in that case I lose @foo.errors
[14:12:24] apeiros: dachinat: a) you update @foo. why do you expect the update not to affect @foo.bars? b) assuming @foo.bars is an AR relation - does it have an order clause? if not - databases do not guarantee any order in a plain select
[14:16:20] dachinat: apeiros: I'm trying to do a nested update of @foo with its first @bar using 'accept_nested_attributes_for'. On some records it works correctly but on others I get differnt 'first.id' of @foo.bars. Params I pass also have correct 'id' passed. I'm not using order clause, I thought .first would always return first record with primary key
[14:19:01] apeiros: dachinat: at least up until rails 4.2, rails does not add a default order clause, no.
[14:19:14] apeiros: so .first will be whichever record the db returns first
[14:20:19] dachinat: apeiros: I have just added default_scope { order(id: :asc) } to Bar model and it started working. thanks for your attention.
[14:22:12] alfiemax: has joined #RubyOnRails
[14:23:32] Jameser: has joined #RubyOnRails
[14:23:51] cabotto: has joined #RubyOnRails
[14:25:51] dminuoso: dachinat: Please dont...
[14:26:53] dachinat: dminuoso: I just did a quick check
[14:27:09] dminuoso: dachinat: default_scope is almost never the adequate solution.
[14:42:02] krawchyk: has joined #RubyOnRails
[14:46:03] veloutin: dachinat: I like to add things like this scope :ordered, -> { order(id: :asc) } instead of default_scope order
[14:55:31] iamarun: has joined #RubyOnRails
[14:56:46] bazfer: has joined #RubyOnRails
[14:56:57] bazfer: has left #RubyOnRails: ()
[14:58:35] morfin60: any idea how generate full url for paperclip attachment?
[14:59:03] alfiemax: has joined #RubyOnRails
[14:59:40] morfin60: i am using jsonapi-resources and defined own method but i have no clue how get full logo URL to return in JSON(with schema + host)
[15:03:03] mices: has joined #RubyOnRails
[15:06:32] waseem_: morfin60: Shouldn't this be it: http://www.rubydoc.info/gems/paperclip/Paperclip/Attachment#url-instance_method
[15:08:08] bazfer: has joined #RubyOnRails
[15:09:01] mices: i wanna add drop shipping logic to spree
[15:09:08] mices: anyone can help me get started
[15:09:27] Jameser: has joined #RubyOnRails
[15:09:52] mices: can i move controllers models and views freely from gem to app
[15:10:16] Jameser: has joined #RubyOnRails
[15:13:22] bazfer_: has joined #RubyOnRails
[15:14:28] hahuang65: has joined #RubyOnRails
[15:15:09] morfin60: waseem_, url returns relative url
[15:15:11] morfin60: not absolute
[15:15:33] bazfer: has joined #RubyOnRails
[15:15:54] borodin: has joined #RubyOnRails
[15:22:35] bazfer_: has joined #RubyOnRails
[15:22:41] waseem_: morfin60: See if this helps: http://www.rubydoc.info/gems/paperclip/Paperclip/Attachment#url-instance_method
[15:22:51] waseem_: morfin60: https://stackoverflow.com/q/12550530/100466 even
[15:28:12] bazfer_: has joined #RubyOnRails
[15:28:57] safetypin: has joined #RubyOnRails
[15:30:49] pwnd_nsfw: mices, you should check out what spree offers for support
[15:30:54] pwnd_nsfw: 'cause we are not a spree support channel
[15:34:35] bazfer_: has joined #RubyOnRails
[15:41:23] bazfer_: has joined #RubyOnRails
[15:45:12] s2013: has joined #RubyOnRails
[15:47:45] bazfer_: has joined #RubyOnRails
[15:52:28] bazfer_: has joined #RubyOnRails
[15:55:34] bazfer: has joined #RubyOnRails
[15:57:37] nogic: has joined #RubyOnRails
[15:58:39] troys: has joined #RubyOnRails
[15:59:51] r0ph: has joined #RubyOnRails
[16:01:00] ebsen: has joined #RubyOnRails
[16:01:03] yehowyada: has joined #RubyOnRails
[16:02:05] gregf_: has joined #RubyOnRails
[16:05:00] bazfer_: has joined #RubyOnRails
[16:07:46] pLaTo0n: has joined #RubyOnRails
[16:08:18] bazfer: has joined #RubyOnRails
[16:10:00] s2013: has joined #RubyOnRails
[16:13:22] alfiemax: has joined #RubyOnRails
[16:20:01] dviola: has joined #RubyOnRails
[16:23:02] yehowyada: has joined #RubyOnRails
[16:23:05] reber: has joined #RubyOnRails
[16:28:44] mostlybadfly: has joined #RubyOnRails
[16:32:00] ebsen: has joined #RubyOnRails
[16:40:55] mikecmpb_: has joined #RubyOnRails
[16:41:13] KeyJoo: has joined #RubyOnRails
[16:42:19] cagomez: has joined #RubyOnRails
[16:45:15] _ritchie_: has joined #RubyOnRails
[16:45:23] jnollette: has joined #RubyOnRails
[16:54:11] mtkd: has joined #RubyOnRails
[16:57:39] kies: has joined #RubyOnRails
[17:01:17] srinidhi: has joined #RubyOnRails
[17:07:40] ur5us: has joined #RubyOnRails
[17:12:28] one_zero: has joined #RubyOnRails
[17:15:18] hahuang65: has joined #RubyOnRails
[17:19:03] one_zero: has joined #RubyOnRails
[17:27:41] desperek: has joined #RubyOnRails
[17:32:08] Or1on: has joined #RubyOnRails
[17:32:12] Cache_Money: has joined #RubyOnRails
[17:37:31] Mvfc: has joined #RubyOnRails
[17:47:34] nogic: has joined #RubyOnRails
[17:49:44] duderonomy: has joined #RubyOnRails
[17:51:30] Or1on: has joined #RubyOnRails
[17:53:22] Alchemical: has joined #RubyOnRails
[18:01:43] Cache_Money: has joined #RubyOnRails
[18:02:16] dviola: has joined #RubyOnRails
[18:04:27] duderonomy: has joined #RubyOnRails
[18:18:50] _ritchie_: has joined #RubyOnRails
[18:20:56] orbyt_: has joined #RubyOnRails
[18:29:32] apeiros: has joined #RubyOnRails
[18:33:35] mikecmpbll: has joined #RubyOnRails
[18:38:56] mostlybadfly: has joined #RubyOnRails
[18:48:40] arBmind: has joined #RubyOnRails
[18:52:50] atrius: has joined #RubyOnRails
[19:01:36] waseem_: has joined #RubyOnRails
[19:04:26] alfiemax: has joined #RubyOnRails
[19:15:58] dviola: has joined #RubyOnRails
[19:16:05] hahuang65: has joined #RubyOnRails
[19:19:03] jnollette: has joined #RubyOnRails
[19:51:15] jobewan: has joined #RubyOnRails
[19:55:38] workmad3: has joined #RubyOnRails
[19:56:52] borodin: has joined #RubyOnRails
[19:57:08] sameerynho: has joined #RubyOnRails
[19:59:21] amperry: has joined #RubyOnRails
[20:00:34] amperry: hi folks, running a test and getting a 'Factory not registered' error, but is there a way to tell *why* a factory failed to register?
[20:01:12] amperry: other than "look at your factory file for a long time", that is; a general command or setting
[20:02:41] dviola: has joined #RubyOnRails
[20:04:14] s2013: has joined #RubyOnRails
[20:21:18] Or1on: has joined #RubyOnRails
[20:22:51] mtkd: has joined #RubyOnRails
[20:30:47] mikecmpb_: has joined #RubyOnRails
[20:34:19] orbyt_: has joined #RubyOnRails
[20:34:28] amperry: If a factories file is syntactically incorrect, then *all* of the factories defined there will fail to load, no?
[20:37:58] mikecmpbll: has joined #RubyOnRails
[20:38:44] alexertech: has joined #RubyOnRails
[20:38:44] kapil___: has joined #RubyOnRails
[20:38:58] cagomez: has joined #RubyOnRails
[20:41:42] dviola: has left #RubyOnRails: ("WeeChat 2.0")
[20:42:46] dviola: has joined #RubyOnRails
[20:51:48] MayerPopp: has joined #RubyOnRails
[21:05:04] amperry: I'm in a position where I've written three tests using FactoryBot, and when I wrote the fourth, I get the error 'ArgumentError: Factory not registered' for *any* new factory I define. I've tried putting FactoryBot.reload in my spec_helper.rb file (no change), as well asFactoryBot.find_definitions (which complains about already-defined factories). I cannot write any more tests.
[21:10:07] cagomez: has joined #RubyOnRails
[21:11:58] conta1: has joined #RubyOnRails
[21:12:14] krawchyk: has joined #RubyOnRails
[21:13:36] Or1on: has joined #RubyOnRails
[21:16:18] cincy_kal: has joined #RubyOnRails
[21:17:10] hahuang65: has joined #RubyOnRails
[21:20:21] cincy_kal: wondering if anyone can help with an autoloading issue? I have a file `app/api_exceptions/base_exception.rb` which is a module and class. the module keeps coming up as unititialized constant. structure looks like https://gist.github.com/jtcrank/94fc2d48ce71c73159007716ed9fd2b4
[21:20:49] cincy_kal: ActiveSupport::Dependencies.autoload_paths lists the api_exceptions directory
[21:32:21] zacts: has joined #RubyOnRails
[21:32:32] quazimodo: has joined #RubyOnRails
[21:36:36] workmad3: has joined #RubyOnRails
[21:37:13] cagomez: has joined #RubyOnRails
[21:53:27] pharma_joe: has joined #RubyOnRails
[21:53:45] quazimodo: has joined #RubyOnRails
[22:20:58] orbyt_: has joined #RubyOnRails
[22:34:02] mtkd: has joined #RubyOnRails
[22:42:11] workmad3: has joined #RubyOnRails
[22:46:30] daed: has joined #RubyOnRails
[23:15:19] rwb-averon: has joined #RubyOnRails
[23:15:23] rwb-averon: hello everyone
[23:15:43] rwb-averon: I have a hairy issue related to callbacks
[23:17:32] rwb-averon: basically, we have some validations that run. before_save, if the record is valid, we want to try to execute an arbitrary SQL command and set a value based on the result
[23:17:59] hahuang65: has joined #RubyOnRails
[23:18:13] rwb-averon: however, if there is an issue w/ what is returned, we want to add to the errors array
[23:18:45] rwb-averon: so basically we have an odd situation where we want to run some validations, execute a query based on the state of the validations to potentially add another validation error, then continue
[23:19:32] rwb-averon: when we try and move the logic from before_save to before_validation, we get a "stack too deep" error after our validation is called many times by active_support/callbacks.rb:221:in `block in halting_and_conditional'
[23:20:25] rwb-averon: here is what is in the model:
[23:21:03] rwb-averon: validate :targeting_criteria_sql_is_safe, if: 'targeting_criteria_in_raw_sql_changed?'
[23:21:16] rwb-averon: before_save :set_targeted_user_ids, if: 'set_targeted_user_ids?'
[23:21:30] rwb-averon: def set_targeted_user_ids?
[23:21:30] rwb-averon: targeting_criteria_in_raw_sql_changed? && targeting_criteria_in_raw_sql.present?
[23:21:53] rwb-averon: def set_targeted_user_ids
[23:21:53] rwb-averon: return unless valid? # *DO NOT EXECUTE RAW QUERY IF TARGETING CRITIERA SQL IS NOT SAFE*
[23:21:56] rwb-averon: query_result = ActiveRecord::Base.connection.exec_query(targeting_criteria_in_raw_sql)
[23:21:59] rwb-averon: user_ids = query_result.rows.flatten.map(&:to_i)
[23:22:04] rwb-averon: case User.where(id: user_ids).pluck(:id)
[23:22:07] rwb-averon: when 'Worker' then Worker.where(id: user_ids).pluck(:id)
[23:22:09] rwb-averon: when 'Employer' then Employer.where(id: user_ids).pluck(:id)
[23:22:14] rwb-averon: if (user_ids - found_ids.to_a).empty?
[23:22:17] rwb-averon: self.targeted_user_ids = user_ids
[23:22:22] rwb-averon: errors.add(:targeting_criteria_in_raw_sql, I18n.t('errors.news.targeting_criteria_in_raw_sql.incorrect_user_type'))
[23:22:27] rwb-averon: rescue Exception => e
[23:22:30] rwb-averon: Rails.logger.info("---- TESTING ---- #{e.message}")
[23:22:32] rwb-averon: Rails.logger.info("---- TESTING ---- #{e.backtrace.join("\n")}")
[23:22:35] rwb-averon: errors.add(:targeting_criteria_in_raw_sql, I18n.t('errors.news.targeting_criteria_in_raw_sql.invalid_sql'))
[23:23:04] rwb-averon: Issue 1 (as written): if all validations pass before set_targeted_user_ids, the record is saved and updated even though these errors are added to the hash
[23:23:23] rwb-averon: Issue 2 (if moved to before_validation): we see stack too deep error as described above
[23:23:44] rwb-averon: perhaps there is a better approach that we should be considering
[23:26:40] baweaver: rwb-averon: use gist next time to paste code. IRC auto-bans for flooding
[23:26:59] baweaver: Now then... *starts reading*
[23:27:39] rwb-averon: thank you baweaver, I'm putting that together now
[23:27:54] baweaver: make sure to shove a .rb extension on it as well rwb-averon
[23:28:02] baweaver: syntax highlighting is nice :D
[23:29:05] alfiemax: has joined #RubyOnRails
[23:30:01] rwb-averon: https://gist.github.com/robert-baldwin/cd11e06894fc691bcf95c01935b02634
[23:30:44] amperry: Hi folks, running a test and getting a 'Factory not registered' error, but is there a way to tell *why* a factory failed to register? Other than "look at your factory file for a long time", that is; a command, spec_helper.rb setting, a logfile to look at?
[23:31:37] baweaver: rwb-averon: quack quack :D
[23:31:45] rwb-averon: it is the `return unless valid?` in first line of set_targeted_user_ids
[23:31:46] baweaver: We make good rubber ducks some times :P
[23:31:56] baweaver: valid? loops back doesn't it?
[23:32:01] rwb-averon: can't call valid? in validations XD
[23:32:17] amperry: I call those quanswers: questions you can answer yourself, but only after you've asked someone else.
[23:32:37] baweaver: I was thinking that might have been it but looks like you beat me to it
[23:32:56] baweaver: amperry: the best are questions driving you mad that you google, just to find out you'd answered the same question earlier with exactly the code you need
[23:33:35] baweaver: rwb-averon: that case statement is odd though
[23:33:42] baweaver: It's doing a case on an array of IDs
[23:34:37] baweaver: It'll never match unless there's some black magic going on there
[23:36:37] kies: has joined #RubyOnRails
[23:43:14] _aeris_: has joined #RubyOnRails
[23:48:01] developish: has joined #RubyOnRails