« Back to channel list

#RubyOnRails - 12 November 2017

« Back 1 day Forward 1 day »
[00:49:07] lunarkitty7: has joined #RubyOnRails
[00:59:06] Technodrome: has joined #RubyOnRails
[01:10:07] mcr: has left #RubyOnRails: ()
[01:24:57] one_zero: has joined #RubyOnRails
[01:48:30] Jason: has joined #RubyOnRails
[01:49:22] Jason: hi all. I have two models, Phone and Carrier. A phone has_one carrier, and a carrier belongs to a phone. When I try to fetch phone.carrier, I get a statementinvalid error: no such column: carriers.item_id
[01:49:51] Jason: so for some reason rails seems to be trying to fetch the phone_id attribute of carriers -- all I want is the carrier object relating to carrier_id
[01:51:17] tamouse__: Jason: are you sure about has_one ? it sounds like it's doing has_many
[01:52:21] Jason: tamouse__: i definitely have has_one in my phone.rb model
[01:52:27] Jason: has_one :carrier
[01:52:39] matthewd: Jason: Those associations don't sound right
[01:53:17] tamouse__: do you have carrier_id in your phone table?
[01:54:24] Jason: tamouse__: i do
[01:54:26] matthewd: has_many/one vs belongs_to is about which table contains the foreign key
[01:54:27] tamouse__: get rid of it
[01:54:42] matthewd: The side with the foreign key belongs_to the other
[01:54:47] tamouse__: the independent table (phones) should not have the foreign key
[01:54:57] Jason: one moment
[01:55:14] matthewd: The side without the foreign key has one|many records referencing it via an FK in their table
[01:55:14] tamouse__: and you want phone_id on the carriers table
[01:55:20] tamouse__: (if you don't have it)
[01:55:24] tamouse__: what matthewd said
[01:55:30] matthewd: tamouse__: No, the associations are wrong, not the columns
[01:55:51] tamouse__: phone has_one :carrier should not have carrier_id on phones
[01:55:55] Jason: that doesn't sound right to me
[01:56:08] Jason: basically, I have phones, and each phone has one carrier
[01:56:18] tamouse__: carrier belongs_to :phone needs to have the phone_id on carriers table
[01:56:22] matthewd: Jason: No, each phone belongs to a carrier
[01:56:37] tamouse__: you described it the opposite way above
[01:56:48] Jason: that's why i just mentioned that -- i think perhaps i'm confused
[01:57:02] Jason: so i could have a group of 5 phones. 1 phone might be on AT&T. 1 phone could be on Verizon.
[01:57:13] Jason: so each phone has one carrier. one carrier has many phones
[01:57:29] matthewd: Phone. belongs. to. carrier.
[01:57:31] tamouse__: ok, then reverse the associations in the models
[01:58:10] Jason: matthewd: i saw, that's what made me think :)
[01:58:24] tamouse__: good catch, matthewd
[02:00:06] matthewd: Part of the reason we ask for real names, and not Foo/Bar, is to catch things like that -- where the real-world relationship can inform what makes sense to model
[02:00:50] Jason: in my effort to try to make it easier to understand perhaps I actually made it more difficult
[02:00:51] Jason: apologies
[02:01:16] tamouse__: nah, you're fine
[02:01:55] matthewd: Yeah, no, I'm saying your models did show the relationship as you intended it (whether they're your true domain models or not)
[02:02:31] Jason: that did it
[02:02:37] Jason: thank you much, matthewd + tamouse__
[02:02:54] tamouse__: hah, don't thank me, i was set to lead you over the cliff
[02:04:15] tamouse__: i will say, sometimes that has_one / belongs_to thing is hard to get. the guide has a section on it
[02:05:33] Jason: well, the worst is i thought i had it down, but that only added to the confusion :-P
[02:06:00] tamouse__: you came to ask, that's the best course sometimes
[02:06:02] Technodrome: has joined #RubyOnRails
[02:14:17] irishfromua: has joined #RubyOnRails
[02:18:57] fcser_: has joined #RubyOnRails
[02:30:17] BloodyMer: has joined #RubyOnRails
[02:36:15] orbyt_: has joined #RubyOnRails
[02:38:21] Technodrome: has joined #RubyOnRails
[02:40:35] guacamole: has joined #RubyOnRails
[03:17:09] Technodrome: has joined #RubyOnRails
[03:21:15] ahrs: has joined #RubyOnRails
[03:24:18] alfiemax_: has joined #RubyOnRails
[03:38:08] Sigyn: has joined #RubyOnRails
[03:41:18] jottr: has joined #RubyOnRails
[03:46:27] irishfromua: has joined #RubyOnRails
[03:51:42] irishfromua: has joined #RubyOnRails
[03:52:46] Jameser: has joined #RubyOnRails
[04:08:36] guacamole: has joined #RubyOnRails
[04:13:39] one_zero: has joined #RubyOnRails
[04:19:11] guacamole: has joined #RubyOnRails
[04:29:02] Technodrome: has joined #RubyOnRails
[04:44:23] sevenseacat: has joined #RubyOnRails
[04:45:54] andrewray: has joined #RubyOnRails
[05:13:45] guacamole: has joined #RubyOnRails
[05:42:08] jottr: has joined #RubyOnRails
[05:55:32] h7br1x: has joined #RubyOnRails
[05:56:34] h7br1x: Can someone help me with this Postgres error please? I think I'm missing a join table? https://gist.github.com/ktdmedia/aaabff3901d83b06968046a665735c3b
[06:22:17] Saukk: has joined #RubyOnRails
[06:27:26] MrCrackPotBuilde: has joined #RubyOnRails
[06:32:16] Saukk: has joined #RubyOnRails
[06:37:38] andrewray: has joined #RubyOnRails
[06:42:28] andrewray: has joined #RubyOnRails
[06:51:50] guacamole: has joined #RubyOnRails
[07:07:31] ali_g: so I know this is a Rails channel but anyone familiar with sinatra?
[07:11:20] Technodrome: has joined #RubyOnRails
[07:26:40] Technodrome: has joined #RubyOnRails
[07:37:04] Technodrome: has joined #RubyOnRails
[07:42:52] iamarun: has joined #RubyOnRails
[07:42:57] jottr: has joined #RubyOnRails
[07:48:09] Technodrome: has joined #RubyOnRails
[07:58:54] Technodrome: has joined #RubyOnRails
[08:03:48] iamarun: has joined #RubyOnRails
[08:09:47] Technodrome: has joined #RubyOnRails
[08:13:41] marr: has joined #RubyOnRails
[08:14:31] Andr3as: good morning.. i have an issue with using paperclip for "nested" attachments on a model while using dropzone.js for the file handling
[08:14:38] Andr3as: i get a NoMethodError - undefined method `[]' for #<ActionDispatch::Http::UploadedFile:0x00007f89b8fb34e0>:
[08:14:48] Andr3as: and am stuck.. googled back and forth but am unable to figure it out.. anyone an idea?
[08:15:00] Andr3as: here's a gist of my code: https://gist.github.com/awunder/a3c433bef528e25f9d48da9263e1cbe6
[08:20:21] Jameser: has joined #RubyOnRails
[08:24:46] r3my: has joined #RubyOnRails
[08:36:47] Exhiled: has joined #RubyOnRails
[08:38:17] arBmind: has joined #RubyOnRails
[08:53:26] duderonomy: has joined #RubyOnRails
[09:01:35] mtkd: has joined #RubyOnRails
[09:09:02] apparition: has joined #RubyOnRails
[09:15:03] sunrunner20: has joined #RubyOnRails
[09:18:26] ur5us: has joined #RubyOnRails
[09:44:03] jottr: has joined #RubyOnRails
[10:23:43] ShalokShalom_: has joined #RubyOnRails
[10:26:02] dviola: has joined #RubyOnRails
[10:26:03] conta: has joined #RubyOnRails
[10:26:33] jottr: has joined #RubyOnRails
[10:27:09] xco: has joined #RubyOnRails
[10:33:53] talentedunicorn: has joined #RubyOnRails
[10:37:01] mikecmpbll: has joined #RubyOnRails
[10:42:18] kapil___: has joined #RubyOnRails
[10:57:18] FernandoBasso: has joined #RubyOnRails
[11:29:31] Ergo: has joined #RubyOnRails
[11:32:00] Jameser: has joined #RubyOnRails
[11:39:52] BloodyMer: has joined #RubyOnRails
[11:58:39] Jameser: has joined #RubyOnRails
[12:17:39] AzaToth: has joined #RubyOnRails
[12:51:32] ^mtkd: has joined #RubyOnRails
[12:55:31] Jameser: has joined #RubyOnRails
[13:18:13] Jameser: has joined #RubyOnRails
[13:40:29] ule: Andr3as: I'd double check if the params you're receiving contains: "screenshots_attributes => screenshots"
[13:40:53] ule: Andr3as: doesn't look you have screenshots_attributes on your view
[13:43:13] Jameser: has joined #RubyOnRails
[13:43:52] Andr3as: ule: well, thats what the dropzone.js modification is for.. see log: "....... Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "tradeplan"=>{"screenshots_attributes"=>{"screenshot"=>...."
[13:44:00] Andr3as: it sends them over
[13:47:42] ule: Andr3as: looks like its going to the first if condition from the dropzone
[13:47:56] ule: this is making it a hash and your code is expecting an array
[13:48:47] ule: so I bet that it goes to this it might work: return "" + this.options.paramName1 + (this.options.uploadMultiple ? "[" + n + "]" : "") + this.options.paramName2 + "";
[13:49:02] Andr3as: well, see log, it is using the second (correct) if.. as: "...name=\"tradeplan[screenshots_attributes][screenshot]\"..."
[13:50:28] Andr3as: i gotta dash.. thank you for your help, though... back later (quite a bit later)
[13:51:44] ule: Try byebug at line 20
[13:51:54] ule: then you type: @tradeplan.valid?
[13:52:03] ule: then @tradeplan.errors.error
[13:52:25] ule: Andr3as: cool, good luck
[14:34:54] conta: has joined #RubyOnRails
[15:00:33] DrYockel: has joined #RubyOnRails
[15:04:29] mtkd: has joined #RubyOnRails
[15:21:36] Technodrome: has joined #RubyOnRails
[16:08:33] andrewray: has joined #RubyOnRails
[16:30:22] bronson: has joined #RubyOnRails
[16:31:57] jottr_: has joined #RubyOnRails
[16:36:28] alfiemax: has joined #RubyOnRails
[16:42:43] xco: has joined #RubyOnRails
[16:42:47] orbyt_: has joined #RubyOnRails
[16:52:08] kapil___: I have table A. table B has many A. table C has many A. how to make tables.?
[17:00:45] Teriance_Viernio: has joined #RubyOnRails
[17:01:08] Papierkorb: has left #RubyOnRails: ("Konversation terminated!")
[17:05:05] Technodrome: has joined #RubyOnRails
[17:05:53] dminuoso: kapil___: Always think the other way around.
[17:05:59] dminuoso: belongs_to expresses a foreign key.
[17:06:51] kapil___: table A belongs to table B, and Table C. is it ok?
[17:08:29] dminuoso: kapil___: In fact many of my tables have at least 2 foreign keys, because most my models belongs_to :created_by, class_name: 'User'
[17:08:34] kapil___: thanks. but I made foreign key required. but it will be one foreign key.
[17:09:00] dminuoso: And if the purpose is to express an m:n relationship, then that's how you do it too.
[17:10:14] kapil___: thanks. I should make both optional.
[17:10:43] kapil___: I want that only one foreign key is filled. how to do it?
[17:11:26] kapil___: table A belongs to table B or C.
[17:11:31] kapil___: but not both.
[17:12:05] dminuoso: kapil___: Use a validation. For the constraint you can use a check constraint if the database has it (postgres does at least)
[17:12:18] dminuoso: If the data is wrong if both are set, be sure to also use a constraint.
[17:12:44] xco: how do i get to use this in my tests? http://edgeapi.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html i tried `include ActiveSupport::Testing::TimeHelpers` so i can use the #freeze_time method but it’s complaning “NoMethodError: undefined method `freeze_time' for..”
[17:12:49] kapil___: can u give me a example. i am new to validation.
[17:12:59] dminuoso: kapil___: http://guides.rubyonrails.org/active_record_validations.html
[17:13:20] dminuoso: xco: You probably included it into the wrong thing.
[17:13:34] dminuoso: xco: My recommentation is to actually just look into the file that defines those helpers.
[17:13:36] xco: yes in the test file where i’m doing the tests
[17:13:47] dminuoso: xco: `include` does not do what you think it doe.s
[17:13:58] dminuoso: xco: include incorporates a Module into another module or classes ancestory.
[17:15:19] xco: where can i include this so i can use in my tests? dminuoso
[17:16:16] dminuoso: xco: Show me your test.
[17:16:29] dminuoso: xco: (Essentially you have to include it in a place, where method lookup ends up finding that module)
[17:17:37] xco: this is what i’m trying https://gist.github.com/xcobar/916e5a885927c609bfef2bf2bff312ae
[17:17:40] dminuoso: xco: I have no idea how the canonical way is honestly. But a simple way would be to refine Kernel, and then activate that refinement for every time where you use it.
[17:18:18] xco: i have no idea what you just said :D :D
[17:18:38] dminuoso: xco: Ah. include it either in a test or describe block.
[17:18:59] dminuoso: xco: https://ruby-doc.org/core-2.4.2/doc/syntax/refinements_rdoc.html
[17:19:41] xco: oh right that link helps, thanks
[17:20:08] dminuoso: Although Im not sure that will actually produce the desired effect.
[17:20:08] xco: even if i get past this, that wouldn’t be the “Rails way” to do it i bet
[17:21:50] dminuoso: xco: Found it
[17:22:07] dminuoso: xco: https://github.com/rails/rails/blob/b6f935bbf9b8470b370ea613dc61218849aabf89/activesupport/lib/active_support/test_case.rb
[17:22:33] dminuoso: If I read this correctly, it should work
[17:23:28] dminuoso: xco: https://github.com/rails/rails/blob/master/activestorage/test/models/blob_test.rb
[17:23:50] dminuoso: xco: what rails version are you using?
[17:24:09] dminuoso: xco: Please gist the full stack trace for your error.
[17:26:51] dminuoso: xco: Ah heh.
[17:27:08] dminuoso: It's not in 5.0
[17:27:36] dminuoso: You are looking at edge documentation.
[17:27:57] dminuoso: Does not appear to be in any release at the moment.
[17:28:30] xco: oh! that makes sense
[17:28:43] dviola: has joined #RubyOnRails
[17:29:20] arBmind: has joined #RubyOnRails
[17:30:40] xco: btw what is “edge” dminuoso
[17:31:00] dminuoso: xco: https://www.youtube.com/watch?v=7nqcL0mjMjw
[17:31:18] xco: thanks ;)
[17:32:29] dminuoso: xco: Edge just means master branch for rails.
[17:44:01] blackcross_: are there LTS versions of ror?
[17:44:15] dminuoso: blackcross_: Yes. 5.1.4
[17:46:01] BloodyMer: has joined #RubyOnRails
[18:25:16] jottr_: has joined #RubyOnRails
[18:41:14] uksio: has joined #RubyOnRails
[18:49:17] Technodrome: has joined #RubyOnRails
[18:50:58] orbyt_: has joined #RubyOnRails
[18:54:22] Dimik: has joined #RubyOnRails
[18:58:46] conta: has joined #RubyOnRails
[19:02:47] guacamole: has joined #RubyOnRails
[19:15:20] Saukk: has joined #RubyOnRails
[19:22:11] weaksauce: has joined #RubyOnRails
[19:22:49] Aherin: has joined #RubyOnRails
[19:24:11] sagax: has joined #RubyOnRails
[19:27:56] shantanoo: has joined #RubyOnRails
[19:34:26] defsdoor: has joined #RubyOnRails
[19:35:38] jottr: has joined #RubyOnRails
[19:55:41] shantanoo: has left #RubyOnRails: ()
[20:04:04] NoGodDamnIdea: has joined #RubyOnRails
[20:07:42] Puffball: has joined #RubyOnRails
[20:10:10] remix2000: has joined #RubyOnRails
[20:10:42] hfp_work: has joined #RubyOnRails
[20:11:38] remix2000: Hey, how should I handle events like notifying user about update or
[20:12:22] remix2000: *post update or birthday for example
[20:18:14] dminuoso: remix2000: Do you want this live or when loading pages?
[20:22:37] NoGodDamnIdea: has joined #RubyOnRails
[20:24:03] eindoofus_: has joined #RubyOnRails
[20:24:12] eindoofus_: when sending a binary upload to an API, what header key/value should one use for the content length? i believe i know what it is but something is failing on my end. wanna make sure i'm not crazy
[20:26:45] dminuoso: eindoofus_: https://tools.ietf.org/html/rfc2616#page-119
[20:27:00] dminuoso: The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, [...]
[20:29:08] NoGodDamnIdea: has joined #RubyOnRails
[20:34:52] marr: has joined #RubyOnRails
[20:43:47] eindoofus_: was thinking it was that, thanks dminuoso
[20:48:06] dminuoso: eindoofus_: normally tools would set this for you though.
[20:59:52] Exhiled: has joined #RubyOnRails
[21:06:51] millz: has joined #RubyOnRails
[21:18:42] Exhiled: has joined #RubyOnRails
[21:21:55] weaksauce: has joined #RubyOnRails
[21:24:48] Exhiled: has joined #RubyOnRails
[21:26:15] jottr: has joined #RubyOnRails
[21:34:12] BloodyMer: has joined #RubyOnRails
[21:37:51] quazimodo: has joined #RubyOnRails
[21:41:38] waseem_: has joined #RubyOnRails
[21:48:56] ali_g: has joined #RubyOnRails
[21:56:58] Radar: GOOD MORNING
[21:57:15] jkwood: Howdy Radar
[21:58:01] Radar: longtime no see jkwood
[21:58:20] Radar: what have you been upi tro?
[21:59:30] jkwood: Oh, this and that. Got a new job I'm starting on the 20th - not Ruby on Rails, but that was always a hobby anyway.
[21:59:44] Radar: "Senior Garbageman"?
[22:00:15] jkwood: Not far! Essentially full-time production support, which is about my favorite thing to do.
[22:00:27] jkwood: Working for Jack Henry, if you've heard of them.
[22:00:30] Radar: oh great :D Monitoring and that sort thing?
[22:00:41] Radar: I haven't heard of them but Google has
[22:00:49] Radar: http://www.geelongcats.com.au/player-profile/jack-henry <- Probably not him
[22:01:15] jkwood: Responding to customer problems - support after support has failed to fix the problem, essentially.
[22:01:29] jkwood: Yeah, not him. Jack Henry and Associates is a banking software company.
[22:02:18] jottr: has joined #RubyOnRails
[22:04:02] dviola: has joined #RubyOnRails
[22:09:43] jottr_: has joined #RubyOnRails
[22:11:24] Radar: jkwood: congrats :)
[22:16:08] remix2000: dminuoso: live, triggered by specific event, eg. model update
[22:16:08] jkwood: Thanks! It's a dream job, at least in the short term :)
[22:19:48] dviola: has joined #RubyOnRails
[22:22:33] dminuoso: remix2000: ActionCable has your back.
[22:28:40] ^mtkd: has joined #RubyOnRails
[22:40:59] gamut: has joined #RubyOnRails
[22:42:29] apeiros: has joined #RubyOnRails
[22:51:10] bronson: has joined #RubyOnRails
[22:54:57] xco: i have a bunch of tests that look like this https://gist.github.com/xcobar/916e5a885927c609bfef2bf2bff312ae all of them test :to, :from, :subject is there a way i can DRY this, factorise it in a nice way?
[22:55:10] xco: would be nice if it’s possible
[22:59:02] arBmind: has joined #RubyOnRails
[23:01:39] bronson: has joined #RubyOnRails
[23:07:19] wethu: has joined #RubyOnRails
[23:08:12] orbyt_: has joined #RubyOnRails
[23:09:31] apeiros: has joined #RubyOnRails
[23:10:13] dminuoso: xco: You can trivially do this by just using ruby.
[23:10:48] xco: dminuoso: yes that what i’m asking help to do
[23:10:55] xco: never done anything close to that before
[23:11:57] dminuoso: xco: Id have to debug minitest a tiny bit since I barely know how it works.
[23:12:03] dminuoso: With rspec its quite easy..
[23:12:22] xco: i don’t use rspec :P
[23:14:48] dminuoso: xco: Im sure you can write assertions just as methods on your spec thing class whatever.
[23:15:06] dminuoso: i.e. def assert_many_things(email); be_crazy_here; end
[23:15:13] dminuoso: And then just call it from your tests.
[23:15:15] apeiros: has joined #RubyOnRails
[23:15:48] dminuoso: If not, I'd just unplug pry, plug it into a test and look at what `self` ends up being.
[23:15:58] dminuoso: And then force something down that classes throat.
[23:17:22] dminuoso: xco: The thing you have to realize, inside a block you are running within some context. It's probably being instance_eval'ed on something (and Im guessing that something ends up being an object of your `class FooTest < ...`
[23:20:34] xco: yeah thought of doing something like def assert_many_things(email); be_crazy_here; end
[23:20:42] xco: but then thought, what if just one asserion fails
[23:21:15] xco: how do i take care of that
[23:21:28] dminuoso: xco: How would this be any different from what you have?
[23:21:35] dminuoso: xco: Methods dont change a thing.
[23:22:14] dminuoso: xco: methods themselves *also* run in the same context. they keep the same `self`, the same instance variables, everything.
[23:22:38] xco: got it, thank you :)
[23:24:06] dminuoso: https://eval.in/898372
[23:25:32] xco: thanks for the snippet!
[23:26:16] dminuoso: xco: https://eval.in/898375
[23:26:19] dminuoso: this might be even more useful
[23:27:50] xco: 👌🏾
[23:28:56] dminuoso: xco: But Im not saying minitest works exactly like that. Perhaps the class of that self is a different one, but whatever it is you can define methods on it.
[23:29:56] xco: yeap i’m doing it to test for myself
[23:36:06] lupine: has joined #RubyOnRails
[23:41:22] apeiros: has joined #RubyOnRails
[23:43:40] mattwithoos: has joined #RubyOnRails
[23:58:48] Technodrome: has joined #RubyOnRails