« Back to channel list

#RubyOnRails - 12 April 2018

« Back 1 day Forward 1 day »
[00:14:19] roshanavand: has joined #RubyOnRails
[00:15:55] harryv: has joined #RubyOnRails
[00:17:53] harryv: has joined #RubyOnRails
[00:19:45] roshanavand: has joined #RubyOnRails
[00:19:53] harryv: has joined #RubyOnRails
[00:20:37] sevenseacat: has joined #RubyOnRails
[00:21:55] harryv: has joined #RubyOnRails
[00:35:37] tejasmanohar: has joined #RubyOnRails
[00:36:11] duderonomy: has joined #RubyOnRails
[00:40:15] LateralO1: has joined #RubyOnRails
[00:41:24] timdotrb: has joined #RubyOnRails
[00:50:57] cagomez: has joined #RubyOnRails
[01:01:53] alfiemax: has joined #RubyOnRails
[01:25:59] duderonomy: has joined #RubyOnRails
[01:35:09] Tempesta: has joined #RubyOnRails
[01:38:36] mroutis: has joined #RubyOnRails
[01:39:57] alfiemax: has joined #RubyOnRails
[01:42:52] kurko_: So, say I have a `ModelA has_one :model_b` and `model_a.model_b = old_record`, I want to do `model_a.model_b = new_record` and have it delete the old_record automatically. Does Rails have that in the latest versions? Or will I have to delete it within the callback transaction myself?
[01:44:29] mroutis: kurko_: deleting as in "deleting the item from the database" ?
[01:45:16] kurko_: mroutis yes, otherwise calling `model_a.model_b` keeps returning the old record (because it's a has_one, it has to choose one)
[01:45:57] mroutis: mhm, kurko_, let me explain me a little bit
[01:47:40] mroutis: model_a.model_b is actually doing a query something like this: "SELECT * FROM model_bs WHERE model_a_id = ?", being "?" the ID of the current instance
[01:49:05] kurko_: mroutis I know these minor things, I've used the has_one thousands of times :D
[01:49:18] mroutis: when you do:
[01:49:30] kurko_: My question is about replacing the old record with the new one, if there's a way in Rails 5+
[01:49:38] kurko_: replacing as in "deleting"
[01:49:59] mroutis: `model_a.model_b = new_record; model_a.save` will change the foreign_key
[01:50:45] mroutis: (something similar as doing: new_record.model_a_id = model_a.id)
[01:51:00] kurko_: oh, it'll change?
[01:51:37] kurko_: ACTION testing this real quick
[01:53:32] kurko_: This is interesting, it deletes the old_record automatically (ModelB.all shows only new_record).
[01:53:40] kurko_: This is new behavior I guess, don't remember seeing this in 4.2
[01:54:35] mroutis: kurko_: that's tricky, tho, I'll confirm it
[01:55:01] kurko_: I'm writing a spec here to make sure this behavior works, so it doesn't break in 6.0 heh
[01:56:02] mroutis: kurko_: do you have a "dependent: :destroy" option?
[01:59:16] kurko_: It works!
[01:59:22] kurko_: Thanks a lot mroutis
[02:00:26] Technodrome: has joined #RubyOnRails
[02:00:53] cagomez: has joined #RubyOnRails
[02:01:15] mroutis: mhm, your welcome, kurko_, hope it has not been confusing
[02:02:20] kurko_: mroutis it's surprising. I've been working so far with a bunch of legacy apps and I've never seen this behavior. In this new app I just tried, it automatically deleted `old_record`.
[02:05:09] mroutis: mhm, yeah, super weird, just checked it in a 4.2 app: https://gist.github.com/mroutis/99277ac2fa52f52671a7ef79024f2289
[02:05:25] mroutis: it just "nullifyies" the foreign_key
[02:05:57] mroutis: I'll try to replicate it in a 5.1 app
[02:06:19] kurko_: not the case on 5.1.4, it deletes the record.
[02:07:45] kurko_: https://cl.ly/3I3V1C2t3j3o
[02:24:38] alfiemax: has joined #RubyOnRails
[02:30:00] timdotrb: has joined #RubyOnRails
[02:37:18] cagomez: has joined #RubyOnRails
[02:40:50] LateralOctober: has joined #RubyOnRails
[02:52:25] Or1on: has joined #RubyOnRails
[02:54:38] hfp_work: has joined #RubyOnRails
[03:15:53] orbyt_: has joined #RubyOnRails
[03:20:34] Saukk: has joined #RubyOnRails
[03:28:34] alfiemax: has joined #RubyOnRails
[03:38:58] kapil___: has joined #RubyOnRails
[03:46:22] Saukk: has joined #RubyOnRails
[03:50:37] desnudopenguino: has joined #RubyOnRails
[03:54:25] Technodrome: has joined #RubyOnRails
[03:58:17] jnollette: has joined #RubyOnRails
[04:13:02] bga57: has joined #RubyOnRails
[04:37:52] nickjj_: has joined #RubyOnRails
[04:41:29] LateralO1: has joined #RubyOnRails
[04:59:15] ur5us: has joined #RubyOnRails
[05:03:13] reber: has joined #RubyOnRails
[05:37:56] KeyJoo: has joined #RubyOnRails
[05:38:46] sidx64: has joined #RubyOnRails
[05:39:06] KeyJoo: has joined #RubyOnRails
[06:00:24] quazimodo: has joined #RubyOnRails
[06:12:50] mtkd: has joined #RubyOnRails
[06:20:58] DoubleMalt: has joined #RubyOnRails
[06:42:04] LateralOctober: has joined #RubyOnRails
[06:45:28] MrCrackPotBuilde: has joined #RubyOnRails
[06:50:13] timdotrb: has joined #RubyOnRails
[07:03:04] defsdoor: has joined #RubyOnRails
[07:16:09] sidx64: has joined #RubyOnRails
[07:19:45] sevenseacat: has joined #RubyOnRails
[07:28:38] schneider: has joined #RubyOnRails
[07:31:36] uksio: has joined #RubyOnRails
[07:35:21] moei: has joined #RubyOnRails
[07:35:31] dionysus69: has joined #RubyOnRails
[08:01:04] mikecmpbll: has joined #RubyOnRails
[08:12:24] KeyJoo: has joined #RubyOnRails
[08:19:36] KeyJoo: has joined #RubyOnRails
[08:21:19] drale2k_: has joined #RubyOnRails
[08:24:21] marr: has joined #RubyOnRails
[08:25:04] andywww: has joined #RubyOnRails
[08:28:48] Andr3as: good morning everyone.. i am a bit stuck with generating a "cumulative sum" - i've the following gist -> https://gist.github.com/awunder/c4b8c40fdaf7101babb6d32922404efd
[08:28:49] Andr3as: anyone an idea how to achieve that?
[08:30:33] andywww: I alo have a question, is https://hastebin.com/atozonomad.rb pushing association functionality too far? If so is there any way I can cast the key before it is used without changing it in the db?
[08:32:43] tbuehlmann: why isn't it an integer in the first place? and why don't you use users.id in the first first place?
[08:35:14] andywww: because this is one of a few systems, the uid was consistent across all systems but for some reason, outside of my control, it was stored as a string
[08:36:16] andywww: i appreciate it looks like a stupid problem to have
[08:42:49] Ergo: has joined #RubyOnRails
[08:42:52] LateralO1: has joined #RubyOnRails
[08:45:07] tbuehlmann: and your application can't deal with its own users.id?
[08:45:49] andywww: thats what i did initially but i was told to change it
[08:46:01] andywww: trust me this is frustrating for me also
[08:46:54] rikkipitt: has joined #RubyOnRails
[08:46:58] dminuoso: Andr3as: Dont think you can do this without window functions in SQL.
[08:48:58] jaffachief: has joined #RubyOnRails
[08:57:01] roshanavand: has joined #RubyOnRails
[08:57:21] dionysus69: is it good practice to have many controllers with few actions or a simple "general" controller for misc actions together?
[08:57:32] Andr3as: dminuoso: thx for looking at it.. anything i could do directly with the hash, maybe?
[08:58:52] tbuehlmann: dionysus69: I prefer having many controllers that somewhat follow the REST idea
[08:59:28] dionysus69: I pretty much meant actions that are not REST at all :)
[08:59:47] dionysus69: for example, some random ajax request action
[09:03:04] tbuehlmann: resources don't have to map to activerecord models, so maybe these actions are indeed RESTable
[09:03:06] sevenseacat: is it not restful? what is it?
[09:03:07] tbuehlmann: have an example?
[09:03:10] ephemer0l: has joined #RubyOnRails
[09:05:11] srinidhi: has joined #RubyOnRails
[09:07:05] dminuoso: tbuehlmann: REST is a bit of a religion.
[09:07:18] dminuoso: tbuehlmann: Consider an action "launchMissiles" - how would you rest it?
[09:07:44] dminuoso: I mean you could think of it as `POST /missile_launch`, question is just why thats helpful.
[09:08:28] tbuehlmann: POST /missile_launches
[09:10:14] dminuoso: tbuehlmann: And now you need to separate the first stage.
[09:11:07] arBmind: has joined #RubyOnRails
[09:14:50] tbuehlmann: well, you could also have a json rpc api in addition to your rest api and now you have to maintain two very different ideas. that's probably not helpful either. having something in between will work, that's for sure, but I'd rather double check for RESTable things before having a trash controller for things that don't match it
[09:15:40] tbuehlmann: often times it's even just using PATCH for enabling/activating stuff instead of a custom route for …/enable
[09:16:16] ianfleeton: has joined #RubyOnRails
[09:17:13] dminuoso: tbuehlmann: Oh yeah, absolutely.
[09:17:43] dminuoso: I mean you could think of stage separation as `POST /missile/1/separation_sequence`..
[09:23:55] sevenseacat: dionysus69: any example?
[09:25:26] dionysus69: action called async_search for example
[09:25:40] sevenseacat: what are you searching?
[09:26:08] dionysus69: would you put it in a general controller with other misc actions or create main_search_controller for it
[09:26:19] dionysus69: let's say users in a search box
[09:26:47] sevenseacat: UsersController#search ?
[09:28:12] dionysus69: hmm ok that sounds fair, but let's say if it were non model action :) like async_sort action
[09:29:22] sevenseacat: (I hope you see where this is going)
[09:29:49] dionysus69: yea :D ok ok I ll mention it later if I come up with a nice example :D
[09:30:38] tbuehlmann: if possible, use the appropriate index action: /users?age=42 or /users?filter[age]=42
[09:32:19] dionysus69: that wouldn't be async though :)
[09:32:58] tbuehlmann: what's async?
[09:39:09] dminuoso: Okay its evident now.
[09:39:15] dminuoso: STM is the way to do concurrency. :o
[09:52:02] kapil___: has joined #RubyOnRails
[10:00:12] ur5us: has joined #RubyOnRails
[10:07:31] mostlybadfly: has joined #RubyOnRails
[10:14:54] ariejan: has joined #RubyOnRails
[10:15:25] dionysus69: tbuehlmann: asynchronous :) ajax :D
[10:22:07] dtzuzu: has joined #RubyOnRails
[10:24:39] marr: has joined #RubyOnRails
[10:25:05] tbuehlmann: and why wouldn't the index action work for that?
[10:28:23] dionysus69: oh you mean you would respond with html differently and for ajax request you would respond with js inside same index action?
[10:29:48] tbuehlmann: yes, that'll work
[10:30:15] tbuehlmann: you could also have a dedicated API for that, but if this is just for some nice UI, it's probably not worth it
[10:30:32] schneider: has joined #RubyOnRails
[10:39:27] deathwishdave: has joined #RubyOnRails
[10:40:16] Ergo: has joined #RubyOnRails
[10:40:22] ferr1: has joined #RubyOnRails
[10:40:32] ferr1: has left #RubyOnRails: ()
[10:42:34] Technodrome: has joined #RubyOnRails
[10:43:22] LateralOctober: has joined #RubyOnRails
[10:59:16] apparition: has joined #RubyOnRails
[11:00:00] mtkd: has joined #RubyOnRails
[11:08:36] Or1on: has joined #RubyOnRails
[11:11:28] workmad3_: has joined #RubyOnRails
[11:20:09] kurko_: has joined #RubyOnRails
[11:33:35] dionysus69: roger :) didn't really think using same action for different purposes based on format :)
[11:36:29] KeyJoo: has joined #RubyOnRails
[11:38:08] Cavallari: has joined #RubyOnRails
[11:44:36] pwnd_nsfw: has joined #RubyOnRails
[11:50:35] rikkipitt: has joined #RubyOnRails
[12:14:04] duderonomy: has joined #RubyOnRails
[12:16:32] GodFather: has joined #RubyOnRails
[12:23:31] errakeshpd: has joined #RubyOnRails
[12:26:48] GodFather: has joined #RubyOnRails
[12:37:41] errakeshpd: how to perform preload on couchmodel ?
[12:39:15] errakeshpd: @users.map{|u| u.order)}
[12:39:22] errakeshpd: @users are array
[12:43:54] LateralO1: has joined #RubyOnRails
[12:47:38] mostlybadfly: has joined #RubyOnRails
[12:58:21] mtkd: has joined #RubyOnRails
[12:59:35] ellcs: has joined #RubyOnRails
[13:12:01] Andr3as: fwiw, you need raw sql to get this done (the cumulative sum from above).. so a combination of https://stackoverflow.com/a/5700744/6844761 (the query for pg) and https://stackoverflow.com/a/14840547 (how to execute raw sql) works
[13:14:15] dminuoso: Andr3as: *sigh* you should never use #execute
[13:14:24] dminuoso: Andr3as: Use #exec_query instead.
[13:14:35] dminuoso: #execute is just a good way to create actual memory leaks.
[13:14:54] dminuoso: It's beyond me how such answers get upvoted so much.
[13:15:31] dminuoso: (or select_rows/select_values if applicable)
[13:15:39] Andr3as: k, thx for letting me know, will look for exec_query
[13:15:44] dminuoso: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-execute
[13:23:20] ianfleeton: has joined #RubyOnRails
[13:26:22] logik-bomb: has joined #RubyOnRails
[13:28:44] logik-bomb: is it possible to do atomic updates to a record (AR) without triggering the full model validation? I'm trying to update it everytime there's a change on the frontend... as in, a field going blur. Thanks
[13:39:01] blitz: has joined #RubyOnRails
[13:50:34] Ergo: has joined #RubyOnRails
[13:50:57] dminuoso: logik-bomb: update_column/save(validate: false)
[13:57:10] Technodrome: has joined #RubyOnRails
[14:02:23] mikecmpb_: has joined #RubyOnRails
[14:04:48] s2013: has joined #RubyOnRails
[14:05:01] ellcs: has joined #RubyOnRails
[14:11:24] sunrunner20: has joined #RubyOnRails
[14:20:50] Technodrome: has joined #RubyOnRails
[14:22:59] logik-bomb: dminuoso: thanks
[14:34:38] KeyJoo: has joined #RubyOnRails
[14:40:44] chouhoulis: has joined #RubyOnRails
[14:46:59] vovs03: has joined #RubyOnRails
[14:51:08] jokke: has joined #RubyOnRails
[14:51:35] jokke: how do i enforce trailing slashes on every path generated by path helpers?
[14:51:42] jokke: in rails 5
[14:52:02] jokke: config.action_controller.default_url_options = { :trailing_slash => true } doesn't seem to work
[14:54:11] KeyJoo: has joined #RubyOnRails
[14:54:17] kapil___: has joined #RubyOnRails
[14:54:36] pwnd_nsfw: jokke, http://www.jumph4x.net/post/16395866916/ensuring-a-trailing-slash-in-rails-wout
[14:55:26] jokke: hm yeah that's one part of it
[14:55:44] jokke: but i wouldn't want each and every link i generate to result in a permanent redirect
[14:56:12] jokke: i just have to read the whole thing :P
[14:57:26] jokke: but this looks like would have to add trailing_slash: true to each and every call of a path helper...
[14:57:46] pwnd_nsfw: if you understand the beauty of ruby, no you don't
[14:57:48] quazimodo: has joined #RubyOnRails
[14:58:14] cam27: has joined #RubyOnRails
[15:00:16] pwnd_nsfw: jokke, there's a gem
[15:00:30] pwnd_nsfw: rack slashenforce
[15:02:01] jokke: pwnd_nsfw: you mean monkeypatching the helpers?
[15:02:13] jokke: i wouldn't see that as beauty
[15:02:25] jokke: (don't get me wrong, i love ruby)
[15:02:50] pwnd_nsfw: Either way, that gem is an option
[15:02:53] jokke: thanks for the gem tip
[15:03:27] jokke: i still don't see how this would affect any rails helpers
[15:03:30] jokke: it's a rack gem
[15:03:54] mtkd: has joined #RubyOnRails
[15:04:16] pwnd_nsfw: and rails is a rack app
[15:09:00] pwnd_nsfw: jokke, you could do it at the server level too (nginx, apache)
[15:10:33] Andr3as: anyone an idea why that interpolation https://gist.github.com/awunder/40e25fa930dabbab04ec2600c9d8d5c8 does not work?
[15:11:03] Andr3as: ah, forget it
[15:11:08] Andr3as: stupid mistake
[15:18:38] mauro1254: has joined #RubyOnRails
[15:18:44] jokke: pwnd_nsfw: yeah i'm gonna do the redirecting on nginx level but i still have to generate correct links
[15:20:16] mauro1254: When connecting to db console (bin/rails dbconsole) I get collation_connection = utf8_general_ci even if in database.yml I specify collation = utf8_unicode_ci, why?
[15:21:55] mauro1254: I use show variables like "%collation%"; to check the values
[15:22:33] unreal_: has joined #RubyOnRails
[15:26:12] orbyt_: has joined #RubyOnRails
[15:28:18] alfiemax: has joined #RubyOnRails
[15:40:03] SteenJobs: has joined #RubyOnRails
[15:42:39] Psy-Q: is there something ready-made that makes error handling in a json-api app easier?
[15:43:59] Psy-Q: otherwise i'll just catch most errors on the ApplicationController so that only very specific ones need to be caught in the specific controllers themselves
[15:47:57] [Butch]: has joined #RubyOnRails
[15:51:23] mtkd: has joined #RubyOnRails
[15:51:54] dviola: has joined #RubyOnRails
[15:52:42] jcarl43: has joined #RubyOnRails
[16:04:40] Or1on: has joined #RubyOnRails
[16:07:53] cagomez: has joined #RubyOnRails
[16:09:24] one_zero: has joined #RubyOnRails
[16:17:05] andrewray: has joined #RubyOnRails
[16:20:56] one_zero: has joined #RubyOnRails
[16:24:12] lessless: has joined #RubyOnRails
[16:25:24] lessless: Hi folks! I'm having a problem with timezones - somehow, upon reading an attribute ActiveRecord sets a weird timezone Time.use_zone(Time.find_zone("GMT")) {puts self.attributes["start_date"] } returns "2017-04-12 00:00:00 +0700" while Time.zone is EST
[16:33:15] troys: has joined #RubyOnRails
[16:34:10] orbyt_: has joined #RubyOnRails
[16:43:50] mtkd: has joined #RubyOnRails
[16:44:00] timdotrb: has joined #RubyOnRails
[16:45:31] drona6: has joined #RubyOnRails
[16:51:46] easzero: has joined #RubyOnRails
[16:53:01] dionysus69: has joined #RubyOnRails
[16:57:09] Technodrome: has joined #RubyOnRails
[17:06:00] Cavallari: has joined #RubyOnRails
[17:11:01] harrycs: has joined #RubyOnRails
[17:13:45] kurko_: has joined #RubyOnRails
[17:18:37] dachi: has joined #RubyOnRails
[17:20:11] dachi: Hello. Do you know if you can get `unconfirmed_email` and other columns from User model in POST /users/sign_in response. There's just id, email, created_at and updated_at there.
[17:20:26] dachi: Sorry, I forgot to mention. I'm talking about Devise.
[17:24:08] cagomez: has joined #RubyOnRails
[17:27:40] mroutis: has joined #RubyOnRails
[17:34:52] SteenJobs: has joined #RubyOnRails
[17:39:57] alfiemax: has joined #RubyOnRails
[17:42:35] mtkd: has joined #RubyOnRails
[17:55:34] mroutis: someone using tpope's vim-rails ?
[18:07:38] sameerynho: has joined #RubyOnRails
[18:08:19] Mia: has joined #RubyOnRails
[18:10:21] sidx64: has joined #RubyOnRails
[18:13:24] sidx64_: has joined #RubyOnRails
[18:16:52] alfiemax: has joined #RubyOnRails
[18:28:24] mikecmpbll: has joined #RubyOnRails
[18:36:08] srinidhi: has joined #RubyOnRails
[18:40:37] chongtxtx: has joined #RubyOnRails
[18:49:47] hammer065: has joined #RubyOnRails
[18:50:37] mtkd: has joined #RubyOnRails
[18:54:05] MrPunkin: has joined #RubyOnRails
[18:54:35] sent-hil: has joined #RubyOnRails
[18:59:22] kurko_: has joined #RubyOnRails
[19:12:56] cagomez: has joined #RubyOnRails
[19:28:22] duderonomy: has joined #RubyOnRails
[19:28:27] kurko__: has joined #RubyOnRails
[19:35:21] cagomez: has joined #RubyOnRails
[19:35:27] alfiemax: has joined #RubyOnRails
[19:40:16] tdy: has joined #RubyOnRails
[19:42:45] hive-mind: has joined #RubyOnRails
[19:51:09] cagomez: has joined #RubyOnRails
[20:02:31] emers2n: has joined #RubyOnRails
[20:04:09] chouhoulis: has joined #RubyOnRails
[20:14:23] cagomez: has joined #RubyOnRails
[20:15:04] Or1on: has joined #RubyOnRails
[20:15:28] kapil___: has joined #RubyOnRails
[20:19:27] mluts: has joined #RubyOnRails
[20:23:08] Technodrome: has joined #RubyOnRails
[20:24:02] workmad3: has joined #RubyOnRails
[20:36:40] SteenJobs: has joined #RubyOnRails
[20:41:41] SteenJobs: has joined #RubyOnRails
[20:55:49] SteenJobs: has joined #RubyOnRails
[21:03:10] mtkd: has joined #RubyOnRails
[21:03:18] SteenJobs: has joined #RubyOnRails
[21:07:21] guacamole: has joined #RubyOnRails
[21:10:03] mroutis: has joined #RubyOnRails
[21:11:10] tdy: has joined #RubyOnRails
[21:14:51] quazimodo: has joined #RubyOnRails
[21:16:34] Rodya_: has joined #RubyOnRails
[21:23:01] guacamole: i'm looking for a good way to duplicate an active record object and carry all its associations to the duplicated object - anyone have experience or ideas around something like that?
[21:28:07] harrycs: has joined #RubyOnRails
[21:32:06] mroutis: has joined #RubyOnRails
[21:36:17] Rodya_: has joined #RubyOnRails
[21:36:24] alfiemax: has joined #RubyOnRails
[21:52:33] cagomez: when using pessimistic locking, what happens if the app is unable to get a lock on the instance?
[21:56:51] easzero: has joined #RubyOnRails
[22:03:23] unreal: has joined #RubyOnRails
[22:14:11] Rodya_: has joined #RubyOnRails
[22:23:19] workmad3: has joined #RubyOnRails
[23:13:35] cagomez: has joined #RubyOnRails
[23:22:19] cagomez: has joined #RubyOnRails
[23:43:23] duderonomy: has joined #RubyOnRails
[23:53:37] mroutis: has joined #RubyOnRails