#RubyOnRails - 06 December 2017
« Back 1 day Forward 1 day »
[02:01:57] Inside: So a question about RoR. I'm running 4.1.2 at work for a couple of internal sites. They work(tm)
[02:12:50] Inside: ... this was my first rails app that I wrote and ran on my PC as a "pirate" server until I finally got IT to let me host it
[02:14:35] Inside: thankfully this app is mostly a collection of dashboards that replaces a ton of excel sheets so it's relatively easy to check the functionality of
[02:14:49] Inside: ... it's my other app which I use for manufacturing production management that terrifies me a bit
[02:17:24] Inside: (I was working as a manufacturing engineer previously with like 25% of my time spent on creating these dashboards/etc -- then I quit -- and they rehired me back after 7 months to come fix all my shit -- except to work on it full time now)
[04:07:24] DaniG2k: I have a question regarding transactions in Rails. In my #create method, we've had an instance where the `if @model.save; do_more_stuff; end` happened twice, concurrently
[04:25:57] havenwood: DaniG2k: From what you've said it sounds more to me like you want to lock rather than do something in a transaction.
[04:26:19] havenwood: DaniG2k: http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html
[04:27:27] havenwood: DaniG2k: Or say more about the issue that's happening do to the concurrent changes?
[04:47:11] DaniG2k: basically, lines 9 and 10 of prize_requests_controller.rb occurred at the same exact time
[04:48:15] DaniG2k: causing the user to have a negative number of points which should actually never occur
[07:58:51] dionysus69: https://gist.github.com/60f8bfcf23c39f537a0d04f717f30763 hello everyone, I am getting this error upon migration on db that has existing users. the problem exists in the find_all block and the error is Validation failed: Email is not an email. any tips appreciated!
[08:06:25] dionysus69: good question, I shouldn't have, how would they register in the first place :|
[08:06:46] dionysus69: but I'll go ahead and double check I suppose, I excluded that possibility at first
[08:07:59] dminuoso: dionysus69: The thing is, the error message is quite clear. Even without seeing a stack trace (which you have failed to include), Im guessing that upon .save! the validation fails for some records.
[08:08:23] dminuoso: So why didn't you already check and *look* at what those records it fails on, and see what's special about them?
[08:08:44] dminuoso: You have been around long enough to be expected to have a basic competency of debugging.
[08:09:58] dionysus69: :) to get which user it fails on I need to add puts user.email, I didn't want to change migration, always ends up me spending lots of time
[08:10:32] dminuoso: dionysus69: You dont need to touch the migration. You can fire up a rails console and just look.
[08:14:16] dminuoso: dionysus69: then do it the hard way and fire up binding.pry if user.save! fails (hint you can just use `binding.pry if !user.save`)
[09:04:14] Andr3as: morning everyone.. i get a NoMethodError (undefined method `inject' for #<ActionController::Parameters:0x00007f50276f3be0>
[09:05:43] dminuoso: Andr3as: Ah. well in 5.1 strong params was encapsulated harder so it acts even less like a hash.
[09:06:33] Andr3as: yes it does.. i googled a bit and found a "dirty hack" with using ".to_unsafe_h.inject"
[09:07:24] Andr3as: and to google for inject is a bit of an uphill battle.. given google thinks i am looking for sql injection
[09:10:00] dionysus69: so is it possible that duplicate email got registered due to race condition? applies to invalid email as well.
[09:10:35] dminuoso: dionysus69: This is why you should use database constraints to enforce constraints.
[09:11:21] dionysus69: PG::UniqueViolation: ERROR: could not create unique index "index_users_on_email"
[09:13:33] dionysus69: or do i need to specify uniqueness on t.string "email", null: false too? like t.string "email", null: false, unique: true?
[09:15:58] dminuoso: https://gist.github.com/anonymous/60f8bfcf23c39f537a0d04f717f30763#file-20171130193159_devise_token_auth_create_users-rb-L18
[09:16:12] dminuoso: And its failing because the data you already have dont satisfy that constraint.
[09:17:12] dionysus69: the app I am working on isn't created by me so, it's weird creator would omit such constraint
[12:28:36] noocx: not ror, but can you tell me please if its ok or need to get rvm is a function? type rvm | head -n 1
[13:47:07] mikeyhew: Is there a way to pass command-line options/arguments to a rails application template (http://guides.rubyonrails.org/rails_application_templates.html)?
[15:29:28] ravster: I'm using actionmailer backed by sidekiq. When I run 'deliver_now', I get an exception, but when I run 'deliver_later', no exception is thrown and nothing shows up in the logs. How do I get exceptions in actionmailer to bubble up?
[15:36:34] ravster: I have fixed the error, and I'm able to send emails successfully now, but I'd like to set this up so that if something goes wrong in the future, I'll get errors showing in the logs and in Sentry (so its easier to debug).
[16:35:51] crova: Greetings everyone! Anyone have an idea why this works on console but not on the app: https://gist.github.com/crova/d8553b17029d53b8087e13f4a9bcd460 I have no error messages whatsoever, the routine just don't get executed. Cheers
[16:55:09] amperry: hi folks, having a problem running 'bundle install', getting error: 'error: cannot open .git/FETCH_HEAD: Permission denied' and a message: If this error persists you could try removing the cache directory '/home/<me>/.bundle/cache/git/best_in_place-4781228d838c514bcc6983421ccace8ddeb89a83'
[17:09:52] noob_on_rails: hey all , if i understand correctly , .uniq will return an unchanged array if there are no changes made , but uniq! will make the same array nil if no changes are made?
[17:12:49] havenwood: noob_on_rails: It won't make the Array `nil` or mutate it at all, but it will return `nil`.
[17:28:53] dminuoso: noob_on_rails: If you dont understand the answer to that question, then you don't understand the GIL.
[17:29:49] dminuoso: Or ruby producing wrong output. Ruby having completely wrong behavior from any threads perspectiev.
[17:30:47] dminuoso: noob_on_rails: No I dont think you understand what I mean. The thing is the actual Ruby VM is not thread safe.
[17:31:00] dminuoso: So race conditions could seriously corrupt the internal ruby state and cause anything basically.
[17:31:29] dminuoso: Im not talking about variables and objects as you see them, but the actual internal state of the program ruby itself.
[17:31:46] dminuoso: noob_on_rails: Because there are cases when the GVL can be unlocked, and that's every time a syscall is made.
[17:32:39] dminuoso: And the most interesting kind of syscall, is blocking syscalls, blocking IO in particular.
[17:33:55] noob_on_rails: it's just frustrating when you want to do complex/big computations you allways have to leave the rails app
[17:34:56] noob_on_rails: never actually got the time to search about it , i have though read that JRuby can run threaded
[17:35:26] dminuoso: Well Ruby can do too (we have gotten native threads a long time ago). But they can do it without a global lock, so they can actually run 2 threads executing ruby code simultaneously.
[17:36:13] dminuoso: Yeah. I mean ruby has that too! But it only works if some of those threads are blocking on IO
[17:36:34] dminuoso: So if you have two threads and one is waiting on a network request, then the other is unlocked and can freely run ruby code.
[17:36:59] dminuoso: Which is why things like puma (which are multithreaded) make sense, because there's a lot of time spent in IO
[17:37:57] noob_on_rails: that's pretty awesome too , i could drop my time a lot even using Raspberries
[17:41:25] dminuoso: noob_on_rails: If you are interested, Koichi (the ruby VM architect) talks about this in here: https://www.youtube.com/watch?v=WIrYh14H9kA
[17:43:19] noob_on_rails: it's unoptimized tho , but still , can't think of a way i'd cut more than 2 mins
[17:46:27] dminuoso: noob_on_rails: And other paradigms exist. Elixir/Erlang for example has 0 concurrency issues.
[17:46:44] noob_on_rails: can you normally use JRuby and put it on rails? sorry for not googling , just asking as a part of the discussion
[17:48:05] workmad3: (and quite easily too... threads as an approach have gotchas and a lot of places you need to be careful with them... the actor concurrency model in erlang/elixir has a lot fewer gotchas for safe operation :) )
[17:48:54] workmad3: noob_on_rails: the 'but' is that you need to be aware that some gems may not work... in particular, you tend to need to use JDBC db adapters instead of the standard db gems
[17:49:13] dminuoso: So you cant just crash JRuby with a race condition of two threads accessing an array.
[18:15:50] amperry: "If this error persists you could try removing the cache directory '/home/<me>/.bundle/cache/git/best_in_place-4781228d838c514bcc6983421ccace8ddeb89a83'error: cannot open .git/FETCH_HEAD: Permission denied"
[18:16:50] noob_on_rails: this is more of a git problem rather than a ror one if i remember correctly
[18:24:20] dminuoso: amperry: My best guess is that at some point you used root (perhaps through sudo). Check the specified file for its owner
[18:24:54] dminuoso: In particular this directory: /home/<me>/.bundle/cache/git/best_in_place-4781228d838c514bcc6983421ccace8ddeb89a83
[18:28:17] noob_on_rails: hmmm , odd i remember having an issue like that, following git's instructions solved it , but better go with what dminuoso is suggesting
[18:39:29] amperry: hrm... it returns quite a bit. Let me see if changing all the file ownership to me works.
[18:45:26] ElDoggo: ActionMailer question: is it safe to override the default delivery_method in a mailer?
[18:46:54] dminuoso: amperry: You could technically delete the entirety of ~/.bundle, though there might be a config inside there.
[18:47:12] noob_on_rails: how can i make this return false if the user is not found User.first.friends.find(12312312312) , instead of ActiveRecord::RecordNotFound: Couldn't find User with 'id'=12312312312 [WHERE "friendshi....
[18:49:48] amperry: dminuoso: there's no config directly in the .bundle directory, but there's a ".bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/info/configuration" and a ".bundle/cache/git/best_in_place-4781228d838c514bcc6983421ccace8ddeb89a83/config"
[18:58:29] dminuoso: I have no idea. RVM is black magic, hooks shell commands like `cd` and others..
[18:59:49] amperry: well, trying it as 'bitnami', and didn't have permission; worried that running 'sudo' will change them to the wrong perms.
[19:01:31] havenwood: amperry: There's an `rvmsudo` command that elevates permissions without dropping Ruby-related environment variables, but it sounds like you should fix the permissions instead of randomly elevating.
[19:02:51] amperry: havenwood: I did not (to the first question); how would I check (to the second)?
[19:03:26] havenwood: amperry: If they're not your RVM Ruby, install the Bundler gem with your RVM Ruby: gem install bundler
[19:04:07] havenwood: amperry: It seems you don't have Bundler installed with your RVM Ruby so when you `bundle` it's falling back to a Bundler gem installed with a system Ruby.
[19:04:50] havenwood: amperry: you have to install Bundler in Ruby versions before 2.5 - it didn't ship with Ruby
[19:05:17] havenwood: amperry: I'd be happy to help sort this out but #ruby or #rvm would probably be better channels.
[19:07:38] dminuoso: mustmodify: You can read about the details how CSRF is implemented here: http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf
[19:09:41] fryguy: does anybody know how `--exclude` works in `bin/rails test` in 5.0+? I can't seem to find the reference to it in rails codebase
[19:12:11] dminuoso: fryguy: https://github.com/seattlerb/minitest/blob/master/lib/minitest.rb#L191-L193
[19:12:14] fryguy: dminuoso: exclude is used to exclude tests from a test run, i'm not entirely sure how it's used (whether it takes filename, fileglobs, or test names) which is why i'm trying to look up the code for it since the doc is lacking
[19:16:31] mattwc: if I have a `parent.childen.save` is that expected to trigger the `before_save` callback on the parent?
[19:20:07] mattwc: they're models, like author and books. But I figured it out, books had an after_save callback that modified author
[19:41:06] jammanbo: Anyone got any tips for tracking down the cause of incorrect line numbers in a stack trace?
[19:47:08] dminuoso: Beyond spring having a different code loaded than on your harddrive, it should not be possible for a stack trace to not fit.
[19:48:04] dminuoso: jammanbo: Normally yes. Can you share your exception and the file where it does not line up in a gist?
[19:48:43] jammanbo: Oh I see. I doubt that's it but sure I'll try anything. I think there's something in either the prawn or prawn-rails gem that is screwing it up ... The reported line is always 7 beyond the actual error (in my code). Really frustrating.
[19:57:55] dminuoso: jammanbo: If the problem still persists, please share the exception including the full stacktrace, as well as the full file where the stacktrace does not line up.
[20:00:47] jammanbo: Actually, I found it. It is the prawn-rails gem. https://github.com/cortiz/prawn-rails/blob/master/lib/prawn-rails/renderer.rb#L6
[20:06:03] dminuoso: If a stacktrace does not line up with actual ruby code it's a ruby bug, so I would like to see it.
[20:09:43] jammanbo: No it's grand, the problem is with the gem. prawn-rails gives lets you create .pdf.prawn templates, but the renderer is effectively prepending those lines to your template, hence when there's an error on line n of your template file, its actually on line n-7 of the template that this gem constructs.
[20:16:37] jammanbo: There's really nothing to see. Error on line 6 of a two line file, https://pastebin.com/wcKPCQUx
[20:32:11] barhum2013: I am having an issue with the following running rspec = capybara-screenshot could not detect a screenshot driver for 'poltergeist_debug’. I have already installed gem poltergeist and phantomjs. Anybody has had a similar issue?
[20:34:15] dminuoso: The valid drivers can be found here: https://github.com/mattheworiordan/capybara-screenshot/blob/master/lib/capybara-screenshot.rb#L146-L193
[20:34:52] dminuoso: barhum2013: Also at this time I would point out the awesomeness of selenium chrome headless.
[20:37:47] barhum2013: dminuoso: Hmmm, it was working before. Just had this error on a new machine I am setting up.
[20:42:34] barhum2013: dminuoso: I just see the following in codebase https://pasteboard.co/GX0hPFZ.png
[20:47:58] crova: Folks, I created a scaffold named "Segment" and I'm getting error "NoMethodError" in Segments#new https://gist.github.com/crova/3cdf069c81cfdf80ccadf809c18b1bb8 anyone got any insight?
[20:51:47] dminuoso: crova: Next time please take the time to a) indent code properly, and b) rename files with file extensions so that syntax hilighting is automatically enabled.
[20:55:29] dminuoso: barhum2013: At any rate. You are using a driver for which capybara-screenshot has no screenshot driver.
[21:23:03] barhum2013: dminuoso: Thanks for the tip, I think I will switch over and clean up this mess.
[21:35:25] helpa: Radar: PLEASE DON'T USE ALL CAPS. IT'S EQUIVALENT TO SHOUTING IN SOMEONE'S EAR FROM 2 INCHES AWAY.
[22:35:46] amperry: I have a model, Ledger, which belongs_to Placement, which has_one Lease and has_many Residents. For efficiency's sake, if I want to do a query that joins to ledger, is this useful --> .joins(leger: [placement: [:residents, :lease]]) <-- or is that handled automatically by the associations?
[22:37:19] amperry: that is to say, I want all of these pulled in on the query, for display in the view.
[23:00:18] xploshioon: hello guys, I am having a problem with ransack, I have this https://gist.github.com/xploshioOn/9b6d75bd48564d8459df46d1961a1083 it seems that the request is doing good, but the query isn't done, and after clicking on search, the form is empty, even when the values are on the url, thanks
[23:11:02] havenwood: xploshioOn: Yeah, that's a potential problem. See: https://reservedwords.herokuapp.com
[23:13:15] Welcius: Hello! I am trying to upload a file submitted using multipart/form-data to a collection of files of a model that uses the Carrierwave gem
[23:13:42] Welcius: Anyone can give me a hand? I've been trying to find a solution for hours and I haven't found anything
[23:20:42] xploshioon: ok, thanks @havenwood, I changed the model, routes, table and all the views that work with that, but still have the problem with ransack, do you see something wrong there? thanks