« Back to channel list

#RubyOnRails - 23 July 2019

« Back 1 day Forward 1 day »
[00:10:52] skryking: has joined #RubyOnRails
[00:12:15] tdy: has joined #RubyOnRails
[00:17:16] NeXTSUN: has joined #RubyOnRails
[00:21:50] tdy: has joined #RubyOnRails
[00:36:20] Exuma: has joined #RubyOnRails
[00:52:48] johnsonch: has joined #RubyOnRails
[01:32:04] s2013: has joined #RubyOnRails
[01:44:42] mochiyoda: has joined #RubyOnRails
[02:33:02] Saukk: has joined #RubyOnRails
[02:37:01] ur5us: has joined #RubyOnRails
[02:42:20] hammer065: has joined #RubyOnRails
[03:16:34] Technodrome: has joined #RubyOnRails
[03:31:12] s2013: has joined #RubyOnRails
[03:35:40] kapilp: has joined #RubyOnRails
[04:07:39] NeXTSUN: has joined #RubyOnRails
[05:13:14] orbyt_: has joined #RubyOnRails
[05:22:12] conta: has joined #RubyOnRails
[05:34:58] Exuma: has joined #RubyOnRails
[05:44:05] beingjohnm: has joined #RubyOnRails
[05:56:08] s00pcan: has joined #RubyOnRails
[06:07:52] s2013: has joined #RubyOnRails
[06:11:50] conta: has joined #RubyOnRails
[06:21:42] schne1der: has joined #RubyOnRails
[06:32:41] corellian: has joined #RubyOnRails
[06:59:40] ZAJDAN: is possible hide in browser URL http://domain.net/controller/method ...the controller/method ...?
[07:00:34] lankanmon: has joined #RubyOnRails
[07:02:45] Exuma: has joined #RubyOnRails
[07:05:14] Exuma: has joined #RubyOnRails
[07:08:04] Exuma: has joined #RubyOnRails
[07:20:37] uksio: has joined #RubyOnRails
[07:22:03] Ropeney: has joined #RubyOnRails
[07:23:29] uksio: has joined #RubyOnRails
[07:23:33] hays: has joined #RubyOnRails
[07:24:43] segy: has joined #RubyOnRails
[07:26:28] arooni: has joined #RubyOnRails
[07:31:41] jefffrails35: has joined #RubyOnRails
[07:53:20] Ergo: has joined #RubyOnRails
[08:00:49] mikecmpbll: has joined #RubyOnRails
[08:11:18] lxsameer: has joined #RubyOnRails
[08:21:15] conta: has joined #RubyOnRails
[08:24:48] Technodrome: has joined #RubyOnRails
[08:42:43] planigan: has joined #RubyOnRails
[08:53:14] dionysus69: ApplicationController.descendants not listing subclasses until I mention them discretely in console
[08:53:23] dionysus69: is it because of lazy loading?
[08:59:31] skryking: has joined #RubyOnRails
[09:02:28] ur5us: has joined #RubyOnRails
[09:03:04] Sylario: has joined #RubyOnRails
[09:07:27] deepreds1: has joined #RubyOnRails
[09:17:44] tdy: has joined #RubyOnRails
[09:47:50] shtirlic: has joined #RubyOnRails
[09:57:37] conta: has joined #RubyOnRails
[10:00:35] schne1der: has joined #RubyOnRails
[10:19:59] conta: has joined #RubyOnRails
[10:57:55] conta: has joined #RubyOnRails
[11:11:57] lankanmon: has joined #RubyOnRails
[11:16:05] ellcs: has joined #RubyOnRails
[11:44:29] xco: has joined #RubyOnRails
[11:44:53] xco: i have an enum on a model like this enum type: { on: 'on', off: 'off' }
[11:45:09] xco: what’ll be the best way to write a method on it that flips the type?
[11:45:32] xco: so that if the type is on, calling the method will return off
[11:45:35] xco: and vice versa
[11:45:43] xco: i thought state machines would be an overkill
[11:48:54] xco: is there a better, sexier way than this? https://gist.github.com/xcobar/dc5ad13637fcf053946c9e9176a7b00a
[12:18:47] conta: has joined #RubyOnRails
[12:37:42] DTZUZO: has joined #RubyOnRails
[13:09:41] conta: has joined #RubyOnRails
[13:17:45] shansen: has joined #RubyOnRails
[13:19:17] tdy: has joined #RubyOnRails
[13:25:42] ikbenhet: has joined #RubyOnRails
[13:31:05] ascarter: has joined #RubyOnRails
[13:44:57] sam1: has joined #RubyOnRails
[13:55:11] conta1: has joined #RubyOnRails
[14:05:12] Linell: xco: that's how I would do it, anyway! Looks sexy to me lol
[14:05:51] xco: Linell: hahaha I thought there’d be a sexier way from more experienced heroes :p
[14:07:44] xco: i ended up doing this anyway https://gist.github.com/xcobar/dc5ad13637fcf053946c9e9176a7b00a, which is slightly more sexier
[14:07:56] xco: slightly sexier*** (- more)
[14:09:22] Linell: ah smart smart
[14:09:38] Linell: I've seen it done with booleans where it's just value = !value
[14:09:45] Linell: but that's cool for an enum
[14:39:55] xco: yeah if it’s a boolean !boolean is perfect
[14:39:56] mcr: has joined #RubyOnRails
[14:44:51] GodFather: has joined #RubyOnRails
[14:46:32] dionysus69: just pushed my first stable version of a gem that makes generating index views as simple as 2 method calls https://github.com/webzorg/lasha
[14:46:58] dionysus69: I know there are table builders but I wanted as bare minimum as possible with No DSL
[14:47:29] jefffrails35: has joined #RubyOnRails
[14:49:04] Linell: dionysus69: nice, congrats!
[14:49:42] NeXTSUN: has joined #RubyOnRails
[14:49:51] xco: has joined #RubyOnRails
[14:51:15] s00pcan: has joined #RubyOnRails
[14:54:24] dionysus69: thanks :) use it if you want, it will be especially useful for admin side, with bootstrap 4 clean tables
[14:55:55] Linell: I'll definitely check it out!
[14:56:16] Linell: Starred it so I'll remember it, too!
[14:58:02] dionysus69: cool! thanks for support! xD
[15:03:57] s2013: has joined #RubyOnRails
[15:06:31] Dbugger: has joined #RubyOnRails
[15:26:50] rikkipitt: has joined #RubyOnRails
[15:32:56] shtirlic: has joined #RubyOnRails
[15:59:12] Exuma: has joined #RubyOnRails
[16:01:15] orbyt_: has joined #RubyOnRails
[16:04:18] lxsameer: has joined #RubyOnRails
[16:09:04] dviola: has joined #RubyOnRails
[16:16:39] P-NuT: has joined #RubyOnRails
[16:17:32] P-NuT: Hi All. I'm using devise for authentication however I have all of my css and js assets located at assets/js/file.js.
[16:18:04] P-NuT: When I reference this in devise it puts /users/ in front of this. Does anyone know how to fix this one?
[16:19:41] Linell: P-NuT: https://stackoverflow.com/questions/15534122/how-to-customize-devise-form-css-in-rails <- would this help at all?
[16:19:43] Inside: how do you reference it in devise?
[16:20:37] Inside: Err - you shouldn't have to do anything - it should automatically bundle up all of your css and js and insert it into the layout that will be used to render the devise view
[16:21:11] Inside: unless you're doing controller specific css and js
[16:23:12] Inside: I.. just said the same stuff as the SO thread lol
[16:23:57] Linell: hahaha it's good to hear it IRL too
[16:24:13] Linell: or *more* irl
[16:55:47] deepreds1: has joined #RubyOnRails
[17:05:52] duderonomy: has joined #RubyOnRails
[17:12:48] Technodrome: has joined #RubyOnRails
[17:22:01] Technodrome: has joined #RubyOnRails
[17:23:37] sam452: has joined #RubyOnRails
[17:45:47] SteenJobs: has joined #RubyOnRails
[18:17:42] orbyt_: has joined #RubyOnRails
[18:28:47] charleswang3: has joined #RubyOnRails
[18:32:27] SteenJobs: if i have a parent object, and before saving that parent object I create and save an association, is that expected to trigger an `after_create` callback on the parent model?
[18:39:36] wyrtell: has joined #RubyOnRails
[18:40:21] wyrtell: Hi friends. Is there a way to run webpack from within an activejob? I need to dynamically build a javascript file based on some user input.
[18:40:47] wyrtell: I could probably just use an erb template in a js file but i was hoping to do something more elaborate with webpack
[18:41:26] Dr_MDMA_MD: has joined #RubyOnRails
[18:50:48] thebetra1: has joined #RubyOnRails
[19:05:59] amperry: has joined #RubyOnRails
[19:06:55] thebetra1: has joined #RubyOnRails
[19:08:19] amperry: hey folks, using Rails 5.2.2, trying to push an app for the first time onto heroku, getting the error: 'Could not detect rake tasks; ensure you can run `$ bundle exec rake -P` against your app'
[19:09:09] amperry: also asks to run 'bundle update --bundler' and "gem install bundler -v '2.0.1.'", which I can do/have done
[19:10:15] amperry: don't know if heroku is too platform specific for this channel
[19:15:25] madprogrammer: has joined #RubyOnRails
[19:17:14] madprogrammer: Hello folks! I'm using webpacker and I can't seem to import any .scss files correctly
[19:17:28] madprogrammer: When I inspect the output file there is something like:
[19:17:30] madprogrammer: <link type="text/css" rel="stylesheet" href="blob:http://localhost:3000/3c3d680e-b43b-4e52-8adc-d76c8ac80064">
[19:18:13] madprogrammer: Does anyone know why it's outputting blobs like that?
[19:30:05] Dr_MDMA_MD: has joined #RubyOnRails
[19:31:10] defsdoor: has joined #RubyOnRails
[19:32:20] Inside: that's odd
[19:32:29] Inside: what does your application.html layout look like
[19:35:27] madprogrammer: Just before closing </head> I have: https://dpaste.de/7ceG
[19:37:09] madprogrammer: The output ends with: https://dpaste.de/WkMd, so I am guessing the blob nodes are dynamically generated by some javascript and not a webpacker issue
[19:38:17] madprogrammer: (the blob <link>s are after that last <script>, in the inspector)
[19:59:52] LtHummus: has joined #RubyOnRails
[20:04:27] deepredsky: has joined #RubyOnRails
[20:14:27] ellcs: has joined #RubyOnRails
[20:41:03] agent_white: has joined #RubyOnRails
[20:48:03] xco: has joined #RubyOnRails
[20:49:29] s2013: has joined #RubyOnRails
[20:57:35] xco: has joined #RubyOnRails
[21:05:22] bambanx: has joined #RubyOnRails
[21:16:15] schne1der: has joined #RubyOnRails
[21:21:59] xco: has joined #RubyOnRails
[21:32:57] glasz: has joined #RubyOnRails
[21:37:05] mlt-: I noticed that if I click on links within SVG, it behaves like an iframe or something. I mean I get different svg it links to loaded instead of opening solely that element. Is it turbolinks or something else in the way?
[21:38:10] mlt-: I use tag :object, type: 'image/svg+xml', data: ... for svg. With image_tag, links don't work:()
[21:40:03] Signum: has joined #RubyOnRails
[21:46:03] catbusters: has joined #RubyOnRails
[21:46:53] LiamW: has joined #RubyOnRails
[21:47:00] LiamW: https://gist.github.com/liamwhite/4b5a3d51ef92153af87b50daedd2ef4b should I expect this?
[21:48:54] LiamW: sorry I am bad at communication
[21:49:02] LiamW: if you run this inline application the test fails
[21:49:25] LiamW: because a nested attribute, as part of a callback chain, is not being created
[21:49:32] LiamW: even though the creation is succesful
[21:50:46] SteenJobs: has joined #RubyOnRails
[21:57:22] Inside: isn't posts_attributes supposed to be an array
[21:57:36] Inside: ie: posts_attributes: [ {body: "foo"}, {body: "bar"}].
[21:58:01] Inside: https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
[22:03:44] Technodrome: has joined #RubyOnRails
[22:03:53] Inside: ok wellThe keys of the hash which is the value for :posts_attributes are ignored in this case. However, it is not allowed to use 'id' or :id for one of such keys, otherwise the hash will be wrapped in an array and interpreted as an attribute hash for a single post.
[22:04:06] Inside: so it doesn't matter
[22:08:07] Inside: well it's curious
[22:09:04] LiamW: that's not what happens
[22:09:12] LiamW: sorry I was eating
[22:09:13] Inside: I'm literally reading from the docs
[22:09:24] LiamW: not only is the hash fine
[22:09:26] LiamW: you have to use it
[22:09:32] LiamW: you can't use an array
[22:09:48] LiamW: otherwise rails will error out on you with undefined method `with_indifferen_access' for Array
[22:10:03] LiamW: which makes sense to me because params is a HWIA
[22:10:22] LiamW: the unexpected behavior is that the Poll isn't being persisted to the database as part of this call
[22:10:27] LiamW: nor are the associated PollOptions
[22:10:45] LiamW: even though the assignment works fine
[22:11:12] LiamW: Poll::Options *
[22:12:05] LiamW: you'll see something along the lines of `"Poll.count" didn't change by 1. (Expected: 1 Actual: 0)`
[22:12:45] LiamW: but the Topic and the Post are being persisted
[22:13:44] LiamW: here's the output https://gist.github.com/liamwhite/4b5a3d51ef92153af87b50daedd2ef4b#file-output-txt
[22:22:58] Inside: ah, I think I know what it might be
[22:31:25] Technodrome: has joined #RubyOnRails
[22:32:58] Inside: absurdly even if I Change your Title to has_many :polls and change your schema it still doesn't want to save
[22:34:41] Inside: but if I take out topic.with_lock it works
[22:34:52] s2013: has joined #RubyOnRails
[22:35:21] Inside: yeah, I get your test to pass if I take out that transactional lock
[22:35:41] Inside: ACTION shakes LiamW 
[22:35:52] LiamW: I figured that out a moment ago as well
[22:35:59] Inside: ACTION shakes LiamW harder
[22:36:09] LiamW: is it a bug?
[22:36:16] LiamW: or just callback hell?
[22:36:42] glasz: has joined #RubyOnRails
[22:37:19] Inside: is it though?
[22:38:13] LiamW: in my real app I need to set some attributes on the post after taking a lock on the topic
[22:38:31] LiamW: my understanding of how this works is that calling with_lock will reload the topic and discard the post it previously built
[22:39:05] LiamW: because the post is already built
[22:39:09] LiamW: and persisted
[22:40:23] Inside: so... with_lock reloads 'topic'
[22:41:08] LiamW: you can subvert the problem by doing Topic.find(id: topic_id).with_lock { |t| ... }
[22:41:21] LiamW: or rather Topic.find(topic_id).with_lock { |t| ... }
[22:42:09] Inside: why do you need to lock?
[22:42:49] Inside: Could you hypothetically wrap everything in a transaction?
[22:42:51] Fernando-Basso: has joined #RubyOnRails
[22:42:59] Inside: instead of starting a new transaction inside your outer transaction?
[22:43:56] LiamW: during post creation, I need to synchronize with other post creation to ensure that all posts get the correct sequence number
[22:44:04] LiamW: which is 1 + the last one
[22:44:21] Inside: sounds rough
[22:44:46] LiamW: accidentally lost the pagination battle a while ago
[22:44:47] Inside: oh, you're trying to order posts within a topic
[22:44:56] LiamW: needed a better way to allow arbitrary page offets
[22:44:59] LiamW: so I assign a sequence number
[22:45:01] LiamW: topic_position
[22:45:09] Inside: why not use a gem ._.
[22:45:27] LiamW: a gem to do what
[22:45:37] Inside: to do your ordering
[22:45:51] LiamW: what do you mean
[22:46:16] Inside: From what I understand: you have a topic, a topic has a bunch of posts, you want to display the posts in order (their topic_position), and you want pagination
[22:46:24] LiamW: I have kaminari
[22:46:28] LiamW: that stuff works fine
[22:46:39] LiamW: but if you try to order by created_at you'll get whipped by the database pretty quick
[22:46:51] LiamW: have some topics with 100k+ posts
[22:46:59] Inside: what do you run?
[22:47:08] LiamW: derpibooru
[22:47:09] Inside: (if not a secret)
[22:47:57] Inside: you can create only one post with your topic, right?
[22:48:06] LiamW: in the real app yes
[22:48:10] LiamW: it limits it to 1
[22:49:03] Inside: you could have a dummy model like 'InitialPost' without any nested attributes, then parse those attributes and manually create 1 of each associated object
[22:49:31] Inside: and then you could, on your topic class store a counter
[22:49:49] Inside: and then in your Post controller, look up the topic, read the counter, and then assign the topic_counter +=1
[22:49:50] LiamW: I chose to add a topic_position integer to posts
[22:50:35] Inside: erm, topic_position would be your topic counter+1, and then when you save you could update the topic_counter
[22:52:29] LiamW: @posts = @topic.posts.where('topic_position >= ?', 25 * (page - 1)).where('topic_position < ?', 25 * page).order(created_at: :asc, id: :asc).includes(:user, topic: :forum).limit(25).to_a
[22:52:33] LiamW: that's how we do pagination
[22:52:36] LiamW: not much fun
[22:52:45] LiamW: works well though
[22:55:18] Inside: you don't like pagination gem? :P
[22:55:36] LiamW: I don't think you understand what I said earlier
[22:55:38] Inside: (will_paginate)
[22:55:38] LiamW: we have kaminari
[22:55:43] LiamW: we even use it here
[22:55:48] LiamW: @posts = Kaminari.paginate_array(@posts, offset: 25 * (page - 1), limit: 25, total_count: @topic.post_count)
[22:56:03] Inside: such is life :)
[22:56:04] LiamW: the problem is that it's not practical to use offset-based pagination for this
[22:56:15] LiamW: for the exact reason I gave you earlier
[22:56:20] Inside: well, you know more than me
[22:56:23] Inside: so I can't be of any help
[22:56:25] LiamW: sorting by created_at will get you whipped by the database very quickly
[22:57:52] LiamW: topic id 15942 has 200106 posts
[22:58:03] LiamW: let's see how long it takes to go to page 8001 if you do a created_at sort
[22:58:15] Inside: I never said to do a created_at sort
[22:58:24] LiamW: you are implying it by saying "use a pagination gem"
[22:59:09] LiamW: Time: 4316.038 ms (00:04.316)
[22:59:14] LiamW: unacceptable for a web request
[22:59:16] Inside: they do pagination based off whatever your ordering statement is
[22:59:39] LiamW: you can do the same with topic_position, you get the same timing issue
[23:00:23] LiamW: still unacceptable 3125.146 ms
[23:01:17] LiamW: how would you solve it
[23:04:51] Inside: (I'm not against using a topic_position column on Post at all, FYI)
[23:07:53] LiamW: so how do you solve arbitrary pagination efficiently using your favorite pagination gem
[23:10:49] Inside: you're right, I think two where statements is probably more efficient than an order+offset+limit
[23:13:10] LiamW: I'm just using one database call here
[23:13:21] Inside: anyway, off to home
[23:14:29] kurly: are you missing an index?
[23:25:06] LiamW: above queries are using a bitmap heap scan combined with a parallel merge sort
[23:25:51] LiamW: first one on the index (topic_id, created_at) and second one on the unique index (topic_id, topic_position)
[23:26:36] LiamW: deep pagination is slow
[23:26:58] LiamW: so if you get to any significant scale, you need to architect around it
[23:27:19] LiamW: limit/offset makes you database very sad
[23:28:26] glasz: has joined #RubyOnRails