« Back to channel list

#RubyOnRails - 31 July 2018

« Back 1 day Forward 1 day »
[00:04:41] prettybTech: has joined #RubyOnRails
[00:05:22] SteenJobs: has joined #RubyOnRails
[00:13:50] eckhardt_: has joined #RubyOnRails
[00:21:20] cagomez: has joined #RubyOnRails
[00:39:13] chouhoulis: has joined #RubyOnRails
[00:46:54] ciro: has joined #RubyOnRails
[00:47:42] CJKinni: has joined #RubyOnRails
[00:55:38] SteenJobs: has joined #RubyOnRails
[00:57:48] krawchyk: has joined #RubyOnRails
[01:07:19] sevenseacat: has joined #RubyOnRails
[01:29:06] kapil___: has joined #RubyOnRails
[01:56:15] ur5us: has joined #RubyOnRails
[01:56:20] SteenJobs: has joined #RubyOnRails
[02:02:44] Saukk: has joined #RubyOnRails
[02:08:11] CJKinni: has joined #RubyOnRails
[02:08:39] alfiemax: has joined #RubyOnRails
[02:12:36] moei: has joined #RubyOnRails
[02:29:53] prettybTech: has joined #RubyOnRails
[02:32:00] rashkov: has joined #RubyOnRails
[02:33:01] rashkov: Is there a way to do this: I have a Participants model. It has a participant_type field, which is set to one of: "student", "teacher", or "volunteer". How would I do a "student has_many: teachers" relationship?
[02:35:26] rashkov: I'm thinking probably a polymorphic association -- Is that the right track?
[02:40:15] alfiemax: has joined #RubyOnRails
[02:40:39] chouhoulis: has joined #RubyOnRails
[02:46:41] krawchyk: has joined #RubyOnRails
[02:54:25] agent_white: has joined #RubyOnRails
[03:09:40] braincrash: has joined #RubyOnRails
[03:21:32] srinidhi: has joined #RubyOnRails
[03:48:13] orbyt_: has joined #RubyOnRails
[03:49:57] prettybTech: has joined #RubyOnRails
[03:53:51] cagomez: has joined #RubyOnRails
[04:03:05] za1b1tsu: has joined #RubyOnRails
[04:10:29] TvL2386: has joined #RubyOnRails
[04:14:15] veloutin: has joined #RubyOnRails
[04:16:26] bitch: has joined #RubyOnRails
[04:57:46] darkhanb: has joined #RubyOnRails
[05:01:04] ur5us: has joined #RubyOnRails
[05:13:21] s2013: has joined #RubyOnRails
[05:19:14] SteenJobs: has joined #RubyOnRails
[05:20:22] alfiemax: has joined #RubyOnRails
[05:40:11] alfiemax: has joined #RubyOnRails
[06:09:56] conta: has joined #RubyOnRails
[06:22:07] snickers: has joined #RubyOnRails
[06:23:58] eckhardt: has joined #RubyOnRails
[06:49:51] Terens: has joined #RubyOnRails
[06:50:13] Terens: has anyone worked on building an authorization system?
[07:00:39] s2013: has joined #RubyOnRails
[07:02:31] Dbugger: has joined #RubyOnRails
[07:09:08] nemesit: has joined #RubyOnRails
[07:09:37] ellcs: has joined #RubyOnRails
[07:22:34] kapil___: has joined #RubyOnRails
[07:22:56] wethu: has joined #RubyOnRails
[07:26:46] lexileo: has joined #RubyOnRails
[07:32:14] cschneid_: has joined #RubyOnRails
[07:39:41] srinidhi: has joined #RubyOnRails
[07:41:02] reber: has joined #RubyOnRails
[07:59:20] mikecmpbll: has joined #RubyOnRails
[08:08:36] ur5us: has joined #RubyOnRails
[08:10:22] lxsameer: has joined #RubyOnRails
[08:11:19] _aeris_: has joined #RubyOnRails
[08:21:48] lxsameer: has joined #RubyOnRails
[08:27:02] _aeris_: has joined #RubyOnRails
[08:28:48] sirensari2: has joined #RubyOnRails
[08:32:37] wethu: has joined #RubyOnRails
[08:37:28] tomaz_b: has joined #RubyOnRails
[08:52:21] unreal_: has joined #RubyOnRails
[08:52:34] deathwishdave: has joined #RubyOnRails
[08:53:43] srinidhi: has joined #RubyOnRails
[08:54:09] wethu: has joined #RubyOnRails
[09:02:29] mengu: has joined #RubyOnRails
[09:02:33] mengu: how does one debug a running rails instance? (puma web server)
[09:03:44] TvL2386: what's the problem?
[09:03:53] jottr: has joined #RubyOnRails
[09:04:06] TvL2386: which env?
[09:04:22] mengu: TvL2386: it's production
[09:04:41] mengu: i've integrated active directory federation services
[09:04:53] mengu: when the user comes back, i have to inspect the response
[09:05:12] mengu: the thing is, the app lives in a docker container, so i cannot change files and restart
[09:05:30] mengu: and that's because docker service starts the app again with the same image, which does not contain my change in files
[09:05:52] mengu: i was thinking maybe i could install byebug or some debugger and intercept in the running process
[09:06:02] mengu: if that's possible
[09:07:55] TvL2386: not sure how much work, but maybe you can create a new image with debugging in it?
[09:08:24] TvL2386: also thinking: maybe you can tcpdump the communication if it's not encrypted (probably not the case)
[09:08:50] TvL2386: maybe you can trigger this communication from the rails console and inspect what's going on?
[09:09:15] mengu: well, i can access the rails console, no problem with that
[09:09:39] mengu: but i receive the response when users are redirected back to my app (from ad fs)
[09:09:51] mengu: is it possible to intercept that controller action from the console?
[09:10:02] TvL2386: I don't think so...
[09:10:19] mengu: alright then
[09:10:20] TvL2386: what you are looking for is changing the code while it is running
[09:10:32] mengu: i should just build the new image with byebug server up and running
[09:10:41] mengu: and then do remote debugging
[09:10:50] TvL2386: hmmmmmmmmmmm
[09:11:04] TvL2386: your dev is not capable of testing the adfs?
[09:11:29] Radar: or add more logging
[09:12:17] TvL2386: yeah anyway: the running process needs to be changed
[09:12:27] TvL2386: in docker...........
[09:12:33] mengu: thank you TvL2386, Radar
[09:12:41] TvL2386: I'm looking for a "how to restart the process currently running in a container"
[09:12:44] Radar: my contribution was minimal. It was TvL2386's work ;)
[09:13:05] TvL2386: but, I don't think that's possible (without building shell scripts using as an entrypoint)
[09:13:19] TvL2386: yw and good luck
[09:14:12] TvL2386: I was also thinking: Modifying the container while it's running, don't --rm it, save it as a temp new image and start it again
[09:14:37] TvL2386: meh... good luck :)
[09:23:47] lexileo: has joined #RubyOnRails
[09:30:47] ur5us: has joined #RubyOnRails
[09:36:54] Cork: has joined #RubyOnRails
[09:47:26] cgfbee: has joined #RubyOnRails
[09:48:42] srinidhi: has joined #RubyOnRails
[09:50:57] lunarkitty7: has joined #RubyOnRails
[10:11:29] argoneus: has joined #RubyOnRails
[10:12:31] thortron: has joined #RubyOnRails
[10:20:46] sameerynho: has joined #RubyOnRails
[10:24:03] wethu: has joined #RubyOnRails
[10:25:06] timwis: has joined #RubyOnRails
[10:26:41] timwis: Morning folks! Trying to determine which ActiveRecord relation type to use for this scenario.. my users have a "rank" column that references a ranks table. There's only 5 ranks but hundreds of users. Should my users model has_one :rank or belongs_to :rank? I definitely don't want deleting a rank to delete associated users, and would assume belongs_to does that. (the user is more important than their rank, kinda thing)
[10:31:07] hammer065: has joined #RubyOnRails
[10:41:48] tbuehlmann: timwis: you probably want this? `User.belongs_to :rank` and `Rank.has_many :users, dependent: :nullify`
[10:42:22] tbuehlmann: this will nullify users.rank (which should be users.rank_id) when a rank is deleted
[10:51:21] timwis: tbuehlmann: interesting; i'd have thought the nullify bit would go in the migration rather than the model
[10:53:04] Sylario: has joined #RubyOnRails
[10:53:49] tbuehlmann: the dependent option is used and ran in ruby-land when destroying a rank object
[11:01:30] hammer065: has joined #RubyOnRails
[11:03:34] theRoUS: has joined #RubyOnRails
[11:03:35] deathwishdave: has joined #RubyOnRails
[11:05:32] theRoUS: rails 5.1 with mongoid. is there a way to have the generic model #find method search for a different field than _id, or in addition to _id? the equivalent of #find_by(:name => val) or #where('$or' => [{:name => val},{:_id => val}]) ?
[11:12:11] Terens: I have a column stored called eg: template. I want to return full object with compiled template , where should I put this logic ?
[11:12:58] GodFather: has joined #RubyOnRails
[11:14:32] timwis: Hey, one more question if you don't mind: I have a rather complex permission logic that queries the database to determine whether the subject is under the actor in a hierarchy. Does it make sense for that query to live in my User model, like a get_permissions_on_group method? I plan to use pundit to lock down my controllers, but need the logic in place first.
[11:14:50] timwis: I'm using the postgres ltree extension for the query, so I expect I'll need a combination of ActiveRecord and a little raw sql
[11:16:32] tbuehlmann: I think having User#group_permissions is okay. if the query or scope is quite big, you could outsource that into a query object or something similar and simply use it in #group_permissions
[11:22:09] timwis: tbuehlmann: interesting. convention is not to use a verb in the method name? i'm new to ruby; coming from JS land
[11:22:22] timwis: not sure what a query object is but i'll google it
[11:28:38] tbuehlmann: timwis: right, we don't need "get" and "set" in ruby. `user.group` is the getter and `user.group=` is the setter (if defined)
[11:32:06] kapil___: has joined #RubyOnRails
[11:33:22] Ergo: has joined #RubyOnRails
[11:35:13] ciro: has joined #RubyOnRails
[11:44:34] chouhoulis: has joined #RubyOnRails
[11:46:15] timwis: tbuehlmann: I might be diving into the deep end of ActiveRecord here a bit too early... I've got this to work in PostgreSQL - would you recommend I just write a raw query, or try to use scopes or something to replicate this in ActiveRecord? https://stackoverflow.com/questions/47360881/how-can-i-determine-permissions-in-a-hierarchical-organization
[11:48:21] timwis: I've got all my models created, and fixtures, and even a couple unit tests ready to go. Just need to write the actual query method. It just happens to be rather complex (and the SO question there is a little simplified to be more concise if you can believe that..)
[11:49:55] nzst: has joined #RubyOnRails
[11:53:40] zmo: I'm writing tests for a controller using rspec, and I'm trying to check the content of a response. I get `expect(response).to render_template("new")` but when I do `expect(response).to have_content("sh!t that should be there")` it fails
[11:54:04] zmo: so I'd like to introspect the HTML that has been rendered, but I don't find what method gives that to me
[11:54:35] zmo: anybody could tell me or give me a good RTFM on how to debug using a response ?
[12:00:28] za1b1tsu: has joined #RubyOnRails
[12:01:15] zmo: hm… I found response.body, but it's ""
[12:01:30] zmo: when I try with a web browser I actually get a page
[12:08:32] alfiemax: has joined #RubyOnRails
[12:14:08] cmartin: has joined #RubyOnRails
[12:17:01] zmo: or, is there a way I can test the instance variables I setup in the controller that I give to the view ?
[12:17:27] zmo: I found I could do : `controller.instance_variable_get(:@that_variable)`
[12:17:29] zmo: and it works
[12:17:34] zmo: but it feels dirty
[12:18:24] cmartin: Morning all. In Rails 5.2 has anyone noticed a difference in delete_if? Have a method that accepts an ActiveRelation that I then run a .to_a.delete_if on. I've confirmed that if I run the delete if the array is modified, however the parent object that had the .to_a ran on it is not.
[12:18:31] conta: has joined #RubyOnRails
[12:20:16] TvL2386: zmo: it is dirty
[12:20:31] chouhoulis: has joined #RubyOnRails
[12:20:52] zmo: TvL2386 - yeah, is there a _clean_ way I can try asserts on the controller's instance variables?
[12:22:12] nzst: cmartin: to_a doesn't modify the parent object, it returns the parent object as an array. So when you chain the method #delete_if it is operating on the return object
[12:23:40] cmartin: Ahh, that makes complete sense. This was an upgrade from 4.2 so that behavior does act differently (maybe a bug in 4.2)
[12:23:47] cmartin: Thank you nzst
[12:23:56] TvL2386: zmo: I'm no guru on the testing subject, but I think you should not test the underlying code. So fetching instance variables from objects and/or inspecting them should not be done. (correct me if I'm wrong!)
[12:24:19] TvL2386: zmo: this also is a workaround for your original problem
[12:24:31] TvL2386: zmo: and unfortunately I don't know how to solve that
[12:24:58] zmo: well, I went that way because I don't get why I got no data from the response's body
[12:25:15] zmo: even though the controller's method actually works 🤔
[12:25:48] ur5us: has joined #RubyOnRails
[12:28:24] TvL2386: zmo gimme a few minutes to check something
[12:30:27] nzst: curl -i <your_endpoint>
[12:30:31] zmo: thank you
[12:30:51] zmo: I got to run for an hour, but I'll check back here when I come back ;)
[12:30:56] augcesar: has joined #RubyOnRails
[12:38:02] za1b1tsu: has joined #RubyOnRails
[13:00:57] fmcgeough: has joined #RubyOnRails
[13:04:56] TvL2386: zmo: I created a simple rails app and I also have your problem
[13:05:37] TvL2386: zmo: the response.class is ActionDispatch::TestResponse and response.body is ""
[13:08:12] TvL2386: zmo: found it! This is what you need, but please read the _comment_ : https://gist.github.com/eliotsykes/5b71277b0813fbc0df56#file-rspec_cheatsheet_controller_spec-rb-L18
[13:08:31] TvL2386: zmo: if you add that `render_views`, response.body will have the generated html
[13:09:57] TvL2386: zmo: https://relishapp.com/rspec/rspec-rails/v/3-1/docs/controller-specs/render-views
[13:12:58] theRoUS: rails 5.1 with mongoid. is there a way to have the generic model #find method search for a different field than _id, or in addition to _id? the equivalent of #find_by(:name => val) or #where('$or' => [{:name => val},{:_id => val}]) ?
[13:40:39] argoneus: has joined #RubyOnRails
[13:53:25] conta1: has joined #RubyOnRails
[13:56:40] Technodrome: has joined #RubyOnRails
[14:05:11] IanMalcolm: has joined #RubyOnRails
[14:12:16] SteenJobs: has joined #RubyOnRails
[14:13:57] srinidhi: has joined #RubyOnRails
[14:16:33] MedubzZ: has joined #RubyOnRails
[14:16:49] MedubzZ: has left #RubyOnRails: ()
[14:24:12] IanMalcolm: has joined #RubyOnRails
[14:25:57] za1b1tsu: has joined #RubyOnRails
[14:26:30] ur5us: has joined #RubyOnRails
[14:34:06] tbuehlmann: timwis: use the raw sql for now and maybe refactor it into AR/arel later on
[14:37:06] snickers: has joined #RubyOnRails
[14:54:35] Technodrome: has joined #RubyOnRails
[14:55:13] nottwo_: has joined #RubyOnRails
[15:03:49] IanMalcolm: has joined #RubyOnRails
[15:05:46] chouhoulis: has joined #RubyOnRails
[15:06:26] chouhoulis: has joined #RubyOnRails
[15:07:01] tdy: has joined #RubyOnRails
[15:08:53] akaiiro: has joined #RubyOnRails
[15:26:48] tcopeland: has joined #RubyOnRails
[15:27:16] za1b1tsu: has joined #RubyOnRails
[15:29:49] ivanskie: has joined #RubyOnRails
[15:38:27] cagomez: has joined #RubyOnRails
[15:45:42] blackcross: has joined #RubyOnRails
[15:45:44] kapil___: has joined #RubyOnRails
[15:51:46] za1b1tsu: has joined #RubyOnRails
[16:03:33] Technodrome: has joined #RubyOnRails
[16:09:28] orbyt_: has joined #RubyOnRails
[16:11:28] IanMalcolm: has joined #RubyOnRails
[16:13:16] beowuff: has joined #RubyOnRails
[16:20:51] lxsameer: has joined #RubyOnRails
[16:21:58] darkhanb: has joined #RubyOnRails
[16:27:18] ur5us: has joined #RubyOnRails
[16:29:59] lxsameer: has joined #RubyOnRails
[16:34:24] alfiemax: has joined #RubyOnRails
[16:36:09] mroutis: has joined #RubyOnRails
[16:36:22] mroutis: has left #RubyOnRails: ()
[16:37:34] lxsameer: has joined #RubyOnRails
[16:40:50] orbyt_: has joined #RubyOnRails
[16:44:58] lxsameer: has joined #RubyOnRails
[16:56:07] agent_white: has joined #RubyOnRails
[16:57:50] mroutis: has joined #RubyOnRails
[17:18:09] mroutis: has joined #RubyOnRails
[17:24:40] prettybTech: has joined #RubyOnRails
[17:24:48] mroutis: has left #RubyOnRails: ()
[17:24:48] lxsameer: has joined #RubyOnRails
[17:31:51] lypsis: has joined #RubyOnRails
[17:45:22] Technodrome: has joined #RubyOnRails
[17:50:51] moei: has joined #RubyOnRails
[17:51:27] zmo: @TvL2386 - yaay \o/
[17:51:31] zmo: @TvL2386 - thank you so much
[17:51:46] zmo: how weird it's not much really visible in the documentation
[17:52:39] eckhardt: has joined #RubyOnRails
[17:53:26] rrichardsr3: has joined #RubyOnRails
[17:56:52] rrichard_: has joined #RubyOnRails
[17:57:17] chouhoulis: has joined #RubyOnRails
[18:01:51] IanMalcolm: has joined #RubyOnRails
[18:04:55] lxsameer: has joined #RubyOnRails
[18:10:50] za1b1tsu: has joined #RubyOnRails
[18:15:29] dtzuzu: has joined #RubyOnRails
[18:25:19] ur5us: has joined #RubyOnRails
[18:40:10] nemesit|znc: has joined #RubyOnRails
[18:43:46] kieranjogrady: has joined #RubyOnRails
[18:44:48] lxsameer: has joined #RubyOnRails
[18:48:50] prettybTech: has joined #RubyOnRails
[18:49:48] kapil___: has joined #RubyOnRails
[18:51:01] mroutis: has joined #RubyOnRails
[18:56:45] Puffball: has joined #RubyOnRails
[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
[19:12:18] tomaz_b: has joined #RubyOnRails
[19:14:35] mroutis: has joined #RubyOnRails
[19:22:22] deathwishdave: has joined #RubyOnRails
[19:25:08] lxsameer: has joined #RubyOnRails
[19:33:24] prettybTech: has joined #RubyOnRails
[19:33:26] Terens: has joined #RubyOnRails
[19:34:57] lxsameer: has joined #RubyOnRails
[19:36:39] Terens: I have a model called eg: XTemplate with several attributes. It has an jsonb attribute called template that has several keys. Only a subset keys should be rendered using a templating engine filling existing placeholders.
[19:36:50] Terens: Which is a clean way to accomplish this?
[19:37:53] Terens: to provide rendered_template
[19:38:05] Terens: should I alter model's attribute?
[19:41:59] GodFather: has joined #RubyOnRails
[19:47:13] ur5us: has joined #RubyOnRails
[19:47:19] dblessing: has joined #RubyOnRails
[19:54:28] hahuang65: anyone know if I can use Postgres' COPY in a Rails migration?
[19:54:51] hahuang65: I seem to get a syntax on the line after COPY
[20:14:25] za1b1tsu: has joined #RubyOnRails
[20:30:18] eckhardt: has joined #RubyOnRails
[20:58:10] chridal: hahuang65: What's the error?
[20:58:21] deathwishdave: has joined #RubyOnRails
[20:58:25] chridal: I'm using a COPY, but in a ActiveRecord::Base.connection.execute
[21:01:23] segy: has joined #RubyOnRails
[21:29:14] lupine: has joined #RubyOnRails
[21:37:00] hightower4: has joined #RubyOnRails
[21:42:47] SteenJobs: has joined #RubyOnRails
[21:52:02] Caerus: has joined #RubyOnRails
[22:00:39] timwis: Hey folks, I'm constructing a complex permissions check query for the current user. It involves a couple nested joins with conditions. Should it be a class method on User, or an instance method? (Since the current user will already be loaded)
[22:21:41] ivanskie: has joined #RubyOnRails
[22:31:37] prettybTech: has joined #RubyOnRails
[22:31:53] Technodrome: has joined #RubyOnRails
[22:35:01] newton: timwis, instance method sounds fine considering the scope is that user anyway
[22:35:26] newton: has joined #RubyOnRails
[22:36:15] timwis: newton: that's what I thought but won't I need to use .joins() ? And that isn't available on instances right?
[22:36:43] newton: timwis, it's also available on the instance
[22:36:47] newton: context matters a little
[22:36:58] timwis: I'm new to rails (coming from node) and haven't been able to find a good example of something like this
[22:37:40] timwis: Would it just be self.joins()? That threw an error for me
[22:38:11] newton: oh jeez - I'm wrong, I don't know where my head is :(
[22:39:28] newton: you could do it either way really then. you could implement it on the user and have it just call self.class.xyz to handle the query, or make it a class method you pass the user to
[22:43:43] timwis: It seems like a relatively common issue though. Any chance there's a name for it I can Google or find an example of?
[22:48:41] MrPunkin: has joined #RubyOnRails
[22:50:09] deathwishdave: has joined #RubyOnRails
[22:53:50] newton: not sure if there is a name for the problem - I'd assume stuff like this is pretty opinionated. If the logic is big or complex, you might consider turning it into a service (another class) that handles it
[22:57:28] wethu: has joined #RubyOnRails
[23:21:20] timwis: Or I could put it in the permission model
[23:47:19] alfiemax: has joined #RubyOnRails
[23:55:14] prettybTech: has joined #RubyOnRails