cjohnson

Activity Graph

Page 1 of 5 | Next »

2018-11-08

[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

2018-11-07

[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

2018-09-04

[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

2018-08-16

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

2018-08-02

[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

2018-08-01

[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`

2018-07-31

[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

2018-07-27

[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

2018-07-26

[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

2018-07-25

[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?

2018-07-20

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

2018-07-19

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

2018-07-18

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

2018-07-11

[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

2018-07-10

[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

2018-07-09

[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

2018-07-02

[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

2018-06-29

[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

2018-06-22

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

2018-06-20

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

2018-06-19

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

2018-06-14

[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

2018-06-12

[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

2018-06-10

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

2018-06-09

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

2018-06-05

[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

2018-05-31

[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

2018-05-30

[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

2018-05-29

[02:47:10] cjohnson: *.net *.split
[02:47:48] cjohnson: has joined #RubyOnRails
[02:48:08] cjohnson: has joined #ruby

2018-05-24

[02:48:29] cjohnson: turn on you mean?
[02:49:21] cjohnson: TBH this is not a job for regular expressions. Or at least not just one regex
[02:49:53] cjohnson: Your problem is |$ allows the +? to terminate early instead of carrying on the next line
[02:50:13] cjohnson: So you can get rid of that but then obviously lose the last match
[02:50:45] cjohnson: w09x: I would maybe split on ^(?=commit[\s\S]+?$)
[02:50:58] cjohnson: I think that might split it into an array of items
[02:52:10] cjohnson: w09x: str.split(/^(?=commit[\s\S]+?$)/)
[02:52:14] cjohnson: this seems to work ok for me
[02:53:44] cjohnson: And then trim any trailing newlines since they don't seem like they are semantically part of the commit message
[02:58:59] cjohnson: It seems to me that using match and looking for another commit is what makes it a bad fit for regex but I suppose if it works it works
[03:03:15] cjohnson: ok that's all for me time to make money
[03:03:54] cjohnson: nooooooooo ok
[03:05:40] cjohnson: why do you hate the world
[05:41:11] cjohnson: Model.joins(:related_model).where(attribute: 'value', related_model_table: { related_model_attribute: 'value'} )

2018-05-16

[06:42:40] cjohnson: Presumably the latter
[06:43:11] cjohnson: Given that it's GEM.bin_path, it seems to me it would be looking at the gems installed and finding the bin_path of hte gem name in question
[06:46:00] cjohnson: seems as though you can specify specific gem versions in requirements
[06:46:01] cjohnson: https://apidock.com/ruby/Gem/bin_path/class
[06:46:10] cjohnson: Though it seems odd to me that it wouldn't pick the one from Gemfile.lock

2018-05-03

[02:38:53] cjohnson: has joined #ruby
[02:39:20] cjohnson: has joined #RubyOnRails

2018-05-02

[23:16:47] cjohnson: *.net *.split

2018-04-30

[15:20:31] cjohnson: Does anybody know if in rails 4, background jobs have activerecord query cache enabled by default?
[15:20:40] cjohnson: And is there a config setting that controls this behavior?
[15:21:05] cjohnson: sidekiq's docs make mention that "as of rails 5, its on by defualt" so that implies to me that before 5, it was not
[15:48:11] cjohnson: I have, what's the question

2018-04-25

[12:25:48] cjohnson: *.net *.split
[12:27:24] cjohnson: has joined #ruby
[12:27:35] cjohnson: has joined #RubyOnRails
[15:01:18] cjohnson: *.net *.split
[15:03:03] cjohnson: has joined #RubyOnRails
[15:03:13] cjohnson: has joined #ruby

2018-04-10

[19:11:15] cjohnson: Is there a gem that supports gpg decryption with passphrases that doesn't rely on passing hte passphrase in via command line?
[19:12:40] cjohnson: Well if you have the passphrase on the command line, anybody can run ps and see it
[19:13:05] cjohnson: So ideally it would write the passphrase to a file and then pass that file path to the gpg command
[19:35:52] cjohnson: Sorry, I had a call
[19:36:13] cjohnson: 2.4 in the coming months but...2.2 for now
[19:36:33] cjohnson: So, let me clarify. This is for a rails app, the web API needs to call gpg to decrypt the incoming encrypted data
[19:37:11] cjohnson: I'm reviewing the PR to add this endpoint and the author wrote the lib which pipes the encrypted data via stdin, and passes the passphrase on the command line using --passphrase "cleartextpassphrase"
[19:37:25] cjohnson: I wanted to suggest an improvement that gets it out of the process list
[19:37:45] cjohnson: So I can't prompt interactively for the passphrase
[19:38:08] cjohnson: One approach might be to have ruby write hte passphrase to a file and then pass that file path to the gpg command
[19:38:32] cjohnson: Seems wonky though. What if the ruby process fails to clean up after itself and the passphrase is left behind
[19:57:07] cjohnson: Oh it turns out this is just a stupid client request
[19:57:12] cjohnson: I thought we were plaintext sending encrypted data
[19:57:23] cjohnson: we're using sftp to transfer the file but they want to transfer double-encrypted shit
[19:57:28] cjohnson: So, meh, I don't care
[21:25:11] cjohnson: Anybody here using webpacker with https: false?

2018-04-06

[01:18:48] cjohnson: WalterPeck: yes. I run the rails app in one container and the db in another

2018-04-05

[22:42:05] cjohnson: Just make your server render the form with those values in the HTML

2018-03-26

[19:50:23] cjohnson: newbie|2: make a syscall to
[19:50:41] cjohnson: timeout 3s grep '$REGEX' /path/to/log/file
[19:50:55] cjohnson: Pipe and convert the resulting text
[19:52:40] cjohnson: has joined #RubyOnRails
[20:47:47] cjohnson: newbie|2: Just make sure you use a tool to properly escape $REGEX as a command line argument
[20:48:01] cjohnson: Don't just concat user input there or they will be able to run arbitrary commands haha
[20:57:11] cjohnson: mrpdd: Don't micro-optimize, if you are having performance problems in your app, profile the entire thing and then optimize by starting with teh biggest time wasters and work your way down
[20:57:15] cjohnson: Don't just pick random things to optimize
[20:57:23] cjohnson: You could actually shoot yourself in the foot

2018-03-16

[22:07:20] cjohnson: *.net *.split
[22:07:54] cjohnson: has joined #ruby

2018-03-15

[11:28:14] cjohnson: has joined #ruby