Activity Graph

Page 1 of 5 | Next »


[14:17:36] cjohnson: Disconnected by services


[15:35:50] cjohnson: has joined #ruby


[01:13:16] cjohnson: Quit: Lost terminal


[12:27:20] cjohnson: Remote host closed the connection
[12:27:33] cjohnson: has joined #ruby


[17:52:34] cjohnson: has joined #ruby


[19:59:29] cjohnson: Quit: Lost terminal


[20:02:20] cjohnson: Can somebody do me a favor and install the xdg gem version 2.2.4 and see if you have an index.rb file?
[20:02:27] cjohnson: ls ~/.rbenv/versions/2.4.6/lib/ruby/gems/2.4.0/gems/xdg-2.2.4/lib/xdg/
[20:02:39] cjohnson: I don't have one, but the xdg.rb file is doing require_relative 'xdg/index'
[20:02:55] cjohnson: Seems like the github repo last change is 7 years ago so I'm rather confused why this is happening for me lol
[20:05:26] cjohnson: Well that's interesting, 2.2.4 was pushed today...
[20:05:47] cjohnson: How do I see where it came from?
[20:24:33] cjohnson: Yeah that's 3.0.0 though, the broken version is 2.2.4
[20:24:41] cjohnson: I made an issue on his new github, I suspect it was a mistake
[20:25:03] cjohnson: From what I can see, the master branch of hte original repository listed 2.2.4 in the HISTORY.md, but no 2.2.4 was ever pushed up to rubygems
[20:25:34] cjohnson: I suspect he took control, saw a mismatch, pushed up without testing that it actually worked and then intended to move forward with his 3.x refactor
[20:25:54] cjohnson: Probably the 2.2.4 version just needs to be yanked, or fixed
[20:26:21] cjohnson: I meant that no 2.2.4 had ever been pushed up until today


[02:18:18] cjohnson: has joined #ruby
[02:18:23] cjohnson: has joined #RubyOnRails


[04:09:37] cjohnson: Quit: Lost terminal


[16:27:50] cjohnson: has joined #RubyOnRails
[16:28:31] cjohnson: I have an association on a model, I want to find the children of the model minus a particular instance
[16:28:44] cjohnson: so parent.children.without(specific_child)
[16:59:26] cjohnson: Best I've got is parent.children - [specific-child]
[16:59:39] cjohnson: Or using .reject { |c| c == specific_child }
[17:04:13] cjohnson: the child is not persisted so that doesn't work
[17:04:18] cjohnson: the query becomes where id IS NOT NULL
[17:04:30] cjohnson: sorry I didn't clarify that
[17:16:19] cjohnson: It's not guaranteed to be the only non-persisted one
[18:21:58] cjohnson: Ok one more question
[18:22:25] cjohnson: I am having a tough time figuring out how I can save changes to children records as part of the parent record save
[18:22:38] cjohnson: Adding a new child works just fine but updating existing ones doesn't
[18:23:02] cjohnson: parent.children.new
[18:23:13] cjohnson: parent.children.first.x = yz
[18:23:14] cjohnson: parent.save
[18:23:21] cjohnson: the new child is saved, but the first child is not updated
[18:23:41] cjohnson: I've tried with and without accepts_nested_attributes_for but I feel like that is more about updating from params
[18:50:57] cjohnson: Oh ok it's actually because I'm using a scope
[18:51:05] cjohnson: parent.children.myScope.first.x = yz
[18:51:06] cjohnson: parent.save
[18:51:08] cjohnson: this doesn't work
[18:51:11] cjohnson: But parent.children.first.x = yz
[18:51:13] cjohnson: parent.save


[21:10:23] cjohnson: has joined #ruby
[21:10:52] cjohnson: Is there a method that returns the first *return value* of the given block that isn't false or nil or something?
[21:11:33] cjohnson: Basically I have a list of values, I want to do a transform on the value but I want to stop at the first return that matches a condition
[21:12:20] cjohnson: A list of secret objects, and I want to call authenticator.authenticate(secret) against each secret, and stop checking additional secrets after I find one where authenticator.authenticate doesn't return false
[21:12:27] cjohnson: I can make it return nil or something else if that helps
[21:12:38] cjohnson: Yes except that find returns the original value
[21:12:45] cjohnson: I want to return the transformed value
[21:13:07] cjohnson: I might have to write *gasp* a loop
[21:13:11] cjohnson: with a break
[21:14:24] cjohnson: Oh wait you can break in find and it'll return the break
[21:17:26] cjohnson: nice that's exactly what I needed
[21:17:33] cjohnson: p.find do |i|
[21:17:40] cjohnson: break transformed_value if i.condition
[22:20:45] cjohnson: phaul: the condition is on the transformed value
[22:20:56] cjohnson: and also that doesn't stop checking after the first match


[17:09:08] cjohnson: Ping timeout: 244 seconds


[19:32:40] cjohnson: What is the ruby construct where you can define a context for overriding child classes
[19:33:06] cjohnson: that's the one thanks
[19:58:27] cjohnson: baweaver: obye
[19:58:38] cjohnson: lol jk happy new year


[22:23:49] cjohnson: I'm pretty sure there's a way to write this in one line without calling the method twice, isn't there?
[22:23:52] cjohnson: foo = super
[22:23:54] cjohnson: return foo if foo


[19:24:47] cjohnson: When request.path = '/foo/bar/baz', is there a better way to get "foo" than request.path.split('/')[1] ?
[19:24:52] cjohnson: foo is not the controller_name
[19:25:04] cjohnson: Is there an array of the path pieces already baked into request somewhere?
[19:27:37] cjohnson: pack = request.path.split('/').reject(&:empty?).first


[18:46:02] cjohnson: I'm taking a handful of existing routes and moving them into a namespace. I need to set up batch redirects for all the old used-to-be top level routes into the namespaced ones
[18:46:08] cjohnson: What's the appropriate way to do this?
[18:46:56] cjohnson: So https://gist.github.com/chrisjohnson/cb921cb44153869b1e5b5c5f1f901bfe these routes used to be top-level. I need to redirect /login to /my-thing/login, /opportunities/foo -> /my-thing/opportunities/key, etc
[19:02:23] cjohnson: Yeah ideally I would not have to redefine every route twice. That said, I can do that, but then how do I handle resource/resources?
[19:02:43] cjohnson: Do I have to convert those to individual get/post/put/etc?
[19:23:21] cjohnson: There's no such thing as a POST redirect right?
[19:23:36] cjohnson: For my single POST route, I will just have to do a direct route match and then redirect after it's posted right


[19:15:46] cjohnson: typeVoid: Seems like that should be def initialize not self.?
[19:29:33] cjohnson: typeVoid: You forgot to include the error in your gist
[19:31:49] cjohnson: Well I don't see fetch_value in your code so not sure how we can help with that
[19:40:22] cjohnson: Oh and that :)
[19:42:37] cjohnson: When are we gonna see refinements get more love
[19:45:19] cjohnson: I mean at the language level
[19:45:25] cjohnson: They're still fairly limited aren't they
[19:45:40] cjohnson: Like for indirect method calls they don't apply


[11:15:47] cjohnson: Ping timeout: 276 seconds


[14:07:34] cjohnson: havenwood: Yeah, anything but nil. But I remembered about `exclusion`
[18:28:15] cjohnson: emptyflask: webpacker will automatically start webpack in dev mode, and then use your rails app to proxy requests into it
[18:28:53] cjohnson: The only thing it won't handle is the websocket connection for live reload, so you would need tp expose the websocket port of the webpack-dev-server to your machine
[18:29:02] cjohnson: But we successfully use it behind a proxy no problem
[18:32:24] cjohnson: Question in rails 4, using accepts_nested_attributes_for, when I'm creating a new parent record + new child records, the child records fail validation because the parent_id is not set
[18:32:48] cjohnson: It seems to me that accepts_nested_attributes_for ought to be passing this down magically but maybe I'm using it wrong. Can I just not use that for new records?
[20:51:41] cjohnson: emptyflask: Hrm, maybe you're right after all
[20:52:00] cjohnson: Looks like webpacker, with the right config, will proxy to your dev server, but we are running it manually on our setup
[20:56:30] cjohnson: I could have sworn I was reading code that started it though. I'm not entirely convinced there isn't some code that does it
[20:56:38] cjohnson: I would read through the webpacker code it's honestly pretty straight forward
[20:56:49] cjohnson: I recently submitted a patch to it to fix some broken behavior


[18:40:13] cjohnson: How can I apply a model validation like presence: true but will allow `false` to be passed in?
[18:40:26] cjohnson: This is a json column so I can't just use `inclusion`


[18:57:43] cjohnson: In rails, I've got Pharmacy, PharmacyOption, and Option. PharmacyOption belongs_to Option and Pharmacy
[18:58:09] cjohnson: I want to generate a form where I iterate every Option, and for each Option, show a fields_for form section for the relevant PharmacyOption if one exists
[18:58:30] cjohnson: And if not, just show the "new" or "blank" form
[18:58:52] cjohnson: Any thoughts on how to do like arbitrary ordering of a fields_for like this?
[19:00:21] cjohnson: Right now I've got f.fields_for :pharmacy_options do |po| ...
[19:00:30] cjohnson: That iterates those PharmacyOption records that already exist


[14:39:11] cjohnson: In ruby, I have a string "foo", and I'm declaring a hash like this: {foo: 'bar'}
[14:39:21] cjohnson: How can I make the key of that hash be dynamic based on the value of a variable
[14:41:37] cjohnson: Yes that, thanks
[14:41:59] cjohnson: Is foovar.to_sym: 'bar' the same?
[14:42:04] cjohnson: I can never quite remember the difference
[14:56:38] cjohnson: "hash rocket" haha


[19:46:31] cjohnson: baweaver: I summon thee
[19:46:36] cjohnson: For your mighty ruby powers
[20:08:34] cjohnson: Ok so here's my problem. Ruby 2.2, rails 4.2. I'm dealing with an ActiveRecord jsonb column
[20:09:25] cjohnson: In my version of rails there is some bad behavior that will only encode the value if it's an array or hash: https://github.com/rails/rails/blob/v4.2.7.1/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb#L20-L26
[20:09:52] cjohnson: I want to override this internal AR method, but only in the context of one model, not for the whole app. So I think the answer is to use refinements
[20:11:02] cjohnson: baweaver: Here's my refinement: https://gist.github.com/chrisjohnson/d21636d2ea339e0875170a642b7feb78 and I am `using Rails4JsonFix` in my model
[20:11:23] cjohnson: baweaver: I can see that the top-level binding.pry is being hit when this refinement is included, but neither of my overridden methods is being called
[20:11:39] cjohnson: Any ideas why? I don't believe they are being called via indirection through `send` or similar
[20:15:31] cjohnson: That gist is in lib/rails4_json_fix.rb and I am `using Rails4JsonFix` @ baweaver
[20:15:39] cjohnson: Which seems to be the way to mix refinements in
[20:17:30] cjohnson: rails magically loads it from lib/rails4_json_fix.rb
[20:18:28] cjohnson: We may have an initializer ethat autoloads all files in lib/*
[20:18:40] cjohnson: It's definitely being loaded since the binding.pry at the top works
[20:18:48] cjohnson: Updated with my model that's using it
[20:22:10] cjohnson: the method I'm overriding? or my refinement method?
[20:22:16] cjohnson: Not quite sure what you mean
[20:24:16] cjohnson: Well let me ask you this then, maybe refinements aren't the way, do you have another idea how to monkeypatch this method but only in certain contexts?
[20:24:43] cjohnson: Damn you rails
[20:25:37] cjohnson: I tried just globally replacing this method but other models in my app depend on the bad behavior haha
[20:25:55] cjohnson: (which has been fixed in rails 5 so we are gonna have a tough time upgrading)
[20:26:50] cjohnson: Ok well maybe then my answer is that I need to make a concern that makes getters/setters for these columns which first json-encode any non-hash non-array value
[20:27:08] cjohnson: LOL exactly
[20:27:45] cjohnson: I tried that too
[20:27:50] cjohnson: This method still gets called I think
[20:28:28] cjohnson: Although frankly I found out later that the validator gem I included was also overriding my setter method so I wonder if maybe it was that all along
[20:28:33] cjohnson: I'll try digging the serializer back out
[20:28:40] cjohnson: So far I've got about 30 commits of "WTFFFFF"
[20:31:26] cjohnson: I had a concern, then a serializer, then a different concern, then I wrote an initializer that just globally overwrote the class with my own hacked version to find that the rest of the app broke
[20:31:44] cjohnson: Then I start down the path of a concern that wraps all scalar values in a hash like {s: "the-real-value"]
[20:31:49] cjohnson: And unwraps them on read
[20:32:04] cjohnson: But then the json-schema validator breaks because I'm validating against a hash but the getter gets a string
[20:32:09] cjohnson: Then the refinement
[20:36:01] cjohnson: Gonna try a concern that double-encodes
[22:59:42] cjohnson: baweaver: I fixed it by writing a serializer that basically supplements the bad behavior in the Json adapter
[23:00:09] cjohnson: baweaver: The Json adapter only serializes hashs and arrays, so my serializer will serialize all other types. it has no impact upon reading since rails can read values from the database just fine


[14:25:49] cjohnson: On rails 4.2, I'm using a postgres jsonb column, and rails knows it's a json column
[14:26:11] cjohnson: When I store the following json document, and then read it back out, I'm getting the json string, not the parsed value: "something"
[14:26:52] cjohnson: I recognize that top-level scalars is not universally supported so I'm wondering if I should expect to have to parse all values in rails, or if rails 4.2 just doesn't recognize top-level scalars yet and I need to add exception cases for that
[14:28:29] cjohnson: For clarification the ruby representation of my value would be "\"something\"" but I expect it to be parsed and become "something"
[14:28:46] cjohnson: Looks like no values are being parsed though
[14:58:42] cjohnson: Inside: That's how bitwise or works...
[14:58:55] cjohnson: It only makes sense on integers, so any non-int is first converted to an int
[14:59:08] cjohnson: Not javascript's fault you are using the wrong tool :)
[14:59:41] cjohnson: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#.7c_%28Bitwise_OR%29
[15:13:01] cjohnson: havenwood: Sorry let me clarify, I seeded a json document directly into the database using SQL, and the full text of the jsonb document is "something"
[15:13:05] cjohnson: no top-level hash
[15:13:19] cjohnson: Then when I go to read that jsonb column, which rails knows to be jsonb, it reads the json string out, which is "something"
[15:13:26] cjohnson: rather than parsing the json into the value something
[15:13:48] cjohnson: So to me it seems like rails is not deserializing jsonb column on read
[15:15:32] cjohnson: I'm on 4.2. I even tested a top-level hash just to be sure it wasn't a case where older rails didn't support top-level scalars
[16:31:44] cjohnson: https://github.com/rails/rails/commit/efaa6e4f79d457c2cdd08cbc56d63bc972a6993c
[16:31:54] cjohnson: It seems like this was a bug in how rails interpreted json columns
[16:32:03] cjohnson: Is there any way to know if this fix was back-ported into the 4.2 line?
[16:32:17] cjohnson: Oh :( I just read the whole commit
[16:34:33] cjohnson: Damn that bites
[17:03:26] cjohnson: I'm writing a concern to fix this in rails 4. In my def self.included, what is the right syntax for calling define_method such that I can define an attr reader/writer on the included class?
[17:03:42] cjohnson: model.define_method json_column do .... ?
[23:18:03] cjohnson: How can I monkeypatch a method that is internal to ActiveRecord?
[23:18:15] cjohnson: ActiveRecord::Type::Json::deserialize
[23:18:43] cjohnson: Can I just make an initializer whose contents are module ActiveRecord module Type class Json def deserialize
[23:18:48] cjohnson: and have it merge with teh original class?


[00:06:58] cjohnson: *.net *.split
[00:15:25] cjohnson: has joined #RubyOnRails
[00:15:32] cjohnson: has joined #ruby


[14:18:12] cjohnson: has joined #ruby
[14:18:20] cjohnson: has joined #RubyOnRails


[05:16:30] cjohnson: *.net *.split
[22:59:45] cjohnson: Ping timeout: 264 seconds


[03:29:43] cjohnson: If you want runtime safety, why are you using a language like ruby in the first place?
[03:47:16] cjohnson: It's probably not proper typing
[03:47:27] cjohnson: in the same way that typescript doesn't actually give you strong typing
[03:47:32] cjohnson: it's just a fancy linter
[03:48:08] cjohnson: Anyway IMO it's not about the tool it's about the work and the environment. Seems so odd to get so emotional about how exactly the language works. If the place seems nice to work, just work there, and learn the tool
[03:48:19] cjohnson: Chances are you will discover some things about it you like


[18:53:56] cjohnson: I have a config/development.json and config/test.json which seem to get loaded
[18:54:01] cjohnson: Is this something native to rails?
[18:54:05] cjohnson: A gem somebody knows about?
[19:39:54] cjohnson: No. Figured it out, it's some internal garbage


[17:31:32] cjohnson: I have an array that I got from JSON.parse, how can I pluck one key from each item in the array if it exists as a new array?
[17:31:47] cjohnson: Like JSON.parse(body).map(&:key) only it's not a symbol
[17:35:01] cjohnson: JSON.parse(body).collect { |e| e['key'] } is the best I've found, but then I'm going to wrap that in an rspec expect so it's a bit cumbersome
[17:42:09] cjohnson: Yeah it's all too long for what I wanted to do with it
[17:42:16] cjohnson: I defined a lambda instead
[17:42:20] cjohnson: get_options = ->(g) { g['options'] }
[17:42:21] cjohnson: expect(JSON.parse(subject.body).map(&get_options)).to all(be_present)
[17:58:32] cjohnson: havenwood: If it's not stdlib I don't want it
[17:58:38] cjohnson: stdlib + rails std lib
[17:58:51] cjohnson: Your monstrosity was not invented here and that is a problem
[18:00:21] cjohnson: Nah but really it's a one-off situation, not worth pulling a gem when a lambda solves it


[21:11:11] cjohnson: Does the module declared in config/application.rb automatically get used somehow? Or do the calls to Rails.application need to be replaced with OurApplication ?
[21:18:58] cjohnson: In a rails 3 -> 4 upgrade we have various calls to OurApplication where the upgrade script seemed to replace those calls with Rails.application
[21:19:11] cjohnson: Just want to make sure Rails.application refers to our specific applciation config and not the default one


[18:09:34] cjohnson: ponzii: er, what?
[18:09:51] cjohnson: react and webpack are entirely different tools
[18:10:06] cjohnson: webpacker is for wrapping webpack up in a convenient railsy way
[18:10:41] cjohnson: webpacker also runs and proxies things to webpack-dev-server
[18:10:51] cjohnson: I don't see how create-react-app solves that problem
[18:11:30] cjohnson: There may be some degree of overlap but no I don't see one as replacing the other
[18:12:33] cjohnson: You haven't used webpack-dev-server?
[18:13:06] cjohnson: It gives you the ability to visit the same asset url in dev vs prod and in dev it proxies to webpack-dev-server but in prod it hits the compiled packs
[18:18:23] cjohnson: webpack-dev-server is a tool that lets you edit the source files and have the packs be regenerated on the fly
[18:18:29] cjohnson: very handy for development


[02:06:07] cjohnson: baweaver I hate you


[16:28:43] cjohnson: I've been using es6 with rails via webpacker
[16:28:45] cjohnson: relatively painlessly


[23:28:26] cjohnson: jrub, that's a brand of lubricant right


[02:12:11] cjohnson: 3 minutes!!!
[02:12:20] cjohnson: that escalated extremely quickly
[03:34:08] cjohnson: You would probably need to include the full stack trace including the line from your own code that is causing it


[15:10:58] cjohnson: syndikate: Well presumably you would need to join the database channel for the relevant DBMS you're using and ask there


[02:47:07] cjohnson: has joined #ruby
[02:47:12] cjohnson: has joined #RubyOnRails


[20:46:05] cjohnson: Remote host closed the connection


[15:07:50] cjohnson: metaprogramming ruby 2 is a book, not tutorial, but pretty good
[15:24:14] cjohnson: I find it to be fairly split


[18:32:11] cjohnson: I have an application that lives under a path prefix behind a proxy that strips the prefix off, so requests to /api/foo are shown as /foo
[18:32:55] cjohnson: I have config.relative_url_root = '/api', but sidekiq doesn't seem to respect that, it reads from env['SCRIPT_NAME']: https://github.com/mperham/sidekiq/blob/f31ed4e699802c510ecff5a10ff77da623df2b4d/lib/sidekiq/web/helpers.rb#L165-L167
[18:33:26] cjohnson: Any clues how I can modify that variable within my app's config so sidekiq will know where it lives?
[18:33:38] cjohnson: When you load sidekiq it tries to load assets at /sidekiq/foo instead of /api/sidekiq/foo
[18:39:29] cjohnson: terens: described in the first paragraph IMO


[19:52:40] cjohnson: Why would you not
[19:52:43] cjohnson: bundle exec rails c
[19:52:47] cjohnson: If you're using bundle


[02:47:48] cjohnson: has joined #RubyOnRails
[02:48:08] cjohnson: has joined #ruby