#RubyOnRails - 21 February 2018
« Back 1 day Forward 1 day »
[00:06:17] Radar: amperry: ffi's latest release is causing those issues. Related thread here: https://github.com/ffi/ffi/issues/607. Seems like a fix will be coming soon.
[00:17:17] FCser: fryguy: Thanks for suggestion. environment.rb is empty / default. But adding perform_deliveries = false inside development.rb appears to made it work! Similar to this answer https://stackoverflow.com/a/30825093
[00:47:26] LiamW: when you deploy to production rails doesn't read from the schema file, it instead reads the schema from the database directly using these queries
[00:50:00] hahuang65: just because rails originates the query, doesn't mean the DB will be unaffected by you killing it, even if it's safe from the rails perspective
[04:54:50] Radar: https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_controller/metal/conditional_get.rb#L245-L250
[04:56:52] machinewar: Radar: this works response.set_header("Cache-Control", "no-store") in Rails 5.1
[05:05:51] machinewar: hmm so this is just general web dev question and prob not best channel, but anyone know how to make sure browser doesn't cache a content-url downloaded via a css :hover for example
[08:22:53] DaniG2k: I'm trying to dynamically create a version of a Carrierwave image if the polymorphic association is of a certain model, and skip it otherwise.
[08:23:14] DaniG2k: Is there a way to dynamically get the model name to create versions so that I don't have to create new uploaders for each model (which seems to defeat the purpose of having a polymorphic Picture model in my opinion)?
[08:23:29] DaniG2k: https://stackoverflow.com/questions/48850510/rails-5-dynamically-get-the-model-name-to-create-versions-with-carrierwave
[09:11:11] Andr3as: does this help? http://andreapavoni.com/blog/2012/3/using-one-carrierwave-image-uploader-with-different-sizes-on-several-models/
[09:16:51] DaniG2k: If you check the comments, Kartikey tanna asked my same question "How to achieve the same for the polymorphic relationship?"
[09:18:44] Andr3as: and if you use a parameter when calling Picture.new? like Picture.new(image: pic, model: 'user')
[09:23:20] Andr3as: interesting that it seems to get the model name to determine the path before saving
[09:24:45] DaniG2k: Carrierwave has been around for years how can I be the only one to have encountered this
[09:25:50] Andr3as: lotsa posts abt polymorphic models and carrierwave.. i think most of 'em use the same processing for each model
[09:27:26] Andr3as: btw.. re caller of the uploader https://stackoverflow.com/questions/5100299/how-to-get-the-name-of-the-calling-method
[09:31:23] DaniG2k: so if I call caller or caller_locations then it might be trying to get pry's caller
[09:34:23] DaniG2k: caller gives me "/Users/me/.rvm/gems/ruby-2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:355:in `eval'"
[11:48:34] fschuindt: Hi there folks, what's the standard behaviour into using a different schema migration table other than "schema_migrations". I'm just trying to run a "rake db:schema:load" task, but using a different table for migration versions, one called "schema_migrations_ar". Any tip?
[13:14:57] syndikate: What is the best way to update around 600K records in rails? I need to recalculate a value and store
[13:16:40] LenPayne: syndikate: Is this a one-time thing, or something you'll repeat over and over again?
[13:18:13] syndikate: Nothing as such, just wanted to know the approach via Rails. This mostly involves timezone updates, so was checking if I could get it done via Rails.
[13:22:35] LenPayne: More time as in running time? Or coding time? I imagine the coding time is Blah.all.each do |b| ... end
[13:24:41] LenPayne: The biggest challenge I've found is that Rails is going to be loading each item one by one, depending on how you approach it. So like the Blah.all does SELECT * FROM blah. But then the .each do does a second SELECT * FROM blah WHERE id = ... for each of them.
[13:26:15] LenPayne: ps- I may be incorrect on the exact SQL translation, but the general effects of using iterators with ActiveRecord is that it makes a LOT of DB requests. You can see this if you turn on SQL debugging.
[13:27:01] LenPayne: We recently had a challenge with our reports suite. We were using find_each too. And it took 50min to run a single report.
[13:27:29] LenPayne: I switched to run a single SQL query instead, to get the aggregate. It sped up to 1-4sec.
[14:03:24] ule: https://github.com/lukkry/active_record_shards_test/blob/5feda3bd707a99e41d23272b4674fbad6e6a3651/db/migrate/20130929141909_create_accounts.rb#L2
[14:04:06] ule: How can I put this line on the ActiveRecord::Migration class in this way where I don't need to put this shard(:none) on all migration files?
[14:04:55] ule: Whats the best way to do this? Creating my own "BaseMigration" and extend this from ActiveRecord::Migration?
[15:09:25] brewops: Hello, I am using Puma to run some Rails apps. We package up ruby along with all of the other gems/dependencies the project needs using bundler. Since Puma then uses the packaged Ruby from our release, after any type of restart/reload the master process holds on to some of the Ruby files in the old project. Is there a way to work around this? Perhaps similar to how unicorn replaces the master?
[15:14:11] dminuoso: Exception: ActiveRecord::AssociationTypeMismatch: House(#70257603296600) expected, got #<House id: 171675, street_id: 171521, zip_code ... >
[15:29:55] cpruitt: I have a project owner that would like some stats/tracking added to his application. Specifically the number of times an item has been displayed. Adding view counters to models concerns me because of race conditions and the slowdown that SQL locking might cause. Adding individual records for each view into another table will bloat very quickly.
[15:30:14] cpruitt: Anyone have any suggestions on a good way to approach this without too much fuss?
[15:36:04] workmad3: cpruitt: I'd typically keep metrics away from the DB by using something like librato, newrelic insights, or a similar self-hosted metrics platform
[15:37:00] workmad3: (we've been setting up a lot of events into a self-hosted snowplow system at work recently, so that we can feed that sort of data into Looker and expose it to internal users for reporting, dashboards, etc.)
[15:39:18] cpruitt: workmad3: Hmmm... In this case I have limited resources (think bare bones hosting & 1 DB) & customer budget to work with so I'm trying to do the best I have with what's available to him. These stats are to be displayed as part of the application (e.g. show a user the number of times their post has been displayed, etc...).
[15:40:39] cpruitt: Even if imperfect, what pitfalls would you expect if I temporarily write individual records into a table for every stat recorded & then use those to update counters before deleting them?
[15:41:16] cpruitt: All that would be done async after page load. Should avoid blocking & keep a stats table to a minimum.
[15:44:37] workmad3: if you're considering doing this async after page load, could you not just queue the increments with a background job queue and do a DB lock in the job?
[15:46:47] workmad3: then a page view just triggers what amounts to an event, and your event processing increments the counter out of band... as long as you're careful with your write transactions and wrap your reads with the right transaction isolation level in PG, you shouldn't hit any slowdowns in reads which can be processed while the writes take place
[15:47:50] cpruitt: workmad3: I guess that's not really much different than what I was proposing. Under high traffic that might lose some opportunity for optimization but honestly this isn't going to have high traffic any time soon and if it does he can pay for some improvements.
[15:48:50] cpruitt: workmad3: "wrap your reads with the right transaction isolation level in PG" <<-- any chance you could elaborate?
[15:49:40] workmad3: cpruitt: chances are you won't need to mess with them, but if you take a look at the docs for transaction isolation levels you should be able to get an idea: https://www.postgresql.org/docs/9.1/static/transaction-iso.html
[15:54:38] workmad3: cpruitt: you may not need to use them even with this, as you might be fine with just using `with_lock` appropriately, as that shouldn't block reads of the data with postgresql
[15:55:47] cpruitt: workmad3: I don't think I will, but like to read through anything new I run across so I'm more familiar in the future. :-)
[16:01:38] mrbubbles: If I want a random user or a random profile, is there a cleaner way than: [User.all.sample, Profile.all.sample].sample
[16:40:16] chuchiperriman: As an example, we are developing a system that show a form in a bootstrap modal
[16:56:21] Sylario: chuchiperriman: do you need JS logic there? Are you doing bloc replacement or something more ?
[17:00:54] mikecmpbll: i have an intermittently failing test which checks a model to see if it's instance methods includes the setter method for an attribute, e.g. User.instance_methods.include?(:email=)
[17:01:40] mikecmpbll: clearly i'm not aware of some mechanism whereby activerecord detects database columns and defines setter/accessor methods
[17:01:59] mikecmpbll: is there a way I can force whatever that process is to happen so my test is robust?
[17:04:57] chuchiperriman: sylario, I call server and show the response (an html form) in a bootstrap modal
[17:06:01] chuchiperriman: then the user saves the form and the server returns a div with info and must replace the original div with this one
[17:07:24] chuchiperriman: sometimes we need to change some icons etc but basically we replace a div with the new content
[17:08:01] Sylario: 2) the JS should only be replace the content of this element with <%= render partial%>
[17:09:41] Sylario: Of course, it's how I do it in project without a JS framework, this is not a Rails convention
[17:09:51] safetypin: has anyone experienced problems accessing path helpers after adding a controller provided by a gem?
[17:09:55] choke: Hey all, working on bringing a php legacy application to rails. having an issue with my factories: https://gist.github.com/jblac/128df32bab746f78376f05ec5428f1e4. I'm sure i'm doing something dumb but no clue what to do.
[17:16:27] safetypin: for some reason i'm getting an "undefined variable or method" error on "root_path" after adding a gem that has generated a controller, but only looking at that controller. the root_path method works on all my other controllers.
[17:40:22] JDeen: Is Rails (3) unable to handle validate uniqueness when multiple child objects are created in a nested form?
[17:41:40] JDeen: I have a form for 'Organization' that has multiple pledges which is unique by 'user_id' and 'year'. The validations work fine. But when I have them created simultaniously (ex: along with an organizaiton) it doesn't fail.
[19:08:03] dminuoso: ActiveRecord::AssociationTypeMismatch: House(#70257609599660) expected, got #<House id: 174264, street_id: 30400 ... > which is an instance of House(#70257577952900)
[19:46:11] cjohnson: I'm having a really strange behavior when using FactoryGirl. I've got a CI process which is: create database, seed some data, run tests
[19:46:33] cjohnson: In the tests, I'm using FactoryGirl.create(:option). Options also happen to be seeded in the seeding process
[19:47:33] cjohnson: For some reason when I create an option with FactoryGirl, the generated insert statement throws a primary key error, that id=2 is already in use. However, the generated query doesn't actually even specify an id
[19:48:12] cjohnson: Through testing I can confirm that if I call it a number of times greater than the number of seeded options, the first X will fail with that error, and then once the id gets high enough, it will stop failing since obviosuly teh id no longer conflicts
[19:48:29] cjohnson: My question is, is there any way rspec or factorygirl are resetting the postgres column sequences or something like that?
[19:50:58] cjohnson: Actually it's the model itself, trying to call Option.create 3 times, the first 2 fail (there are 2 Options seeded) and the third succeeds
[19:52:27] cjohnson: Option.create(description: 'foo') gives me id:1, a seocnd call gives me id:2, a third gives me id:3
[19:52:47] cjohnson: How does the model come up with the id if the insert (returning id) is failing?
[20:07:47] cjohnson: Issue turned out to be that my seeds were specifying the ID manually and that doesn't update the postgres sequence
[20:07:57] cjohnson: so when the next insert happens and it pulls from the sequence, the pulled id is already used
[21:58:08] dminuoso: 20:08 dminuoso | ActiveRecord::AssociationTypeMismatch: House(#70257609599660) expected, got #<House id: 174264, street_id: 30400 ... > which is an instance of House(#70257577952900)
[21:58:37] dminuoso: This happened out of a freshly spun up rails console, spring was shot in the head just before.
[22:10:58] Radar: dminuoso: I've seen this error many times before but forget what causes it eac h time
[23:18:13] iWaffles: So with ActiveStorage I'm able to upload files, I see them in S3, however I'm not seeing them in the `active_storage_attachments` table that it created. I can't see any errors in the web console or in the terminal – does anyone know how to fix this?
[23:23:55] capin: Radar: yeah man, finished up the switch the other day, I can successfully perform GET / POST / DELETE actions to my API using `curl` and created a custom `download` route / method. Overall it went rather well. I removed a bunch of BS to ie, coffeescript, jquery, and bootstrap.
[23:55:37] mrbubbles: Has anyone ever seen where you install a gem and it starts kicking off about sqlite3 not being installed?