#RubyOnRails - 30 August 2017
« Back 1 day Forward 1 day »
[01:37:47] Zinefer: i'm doing a bit of complicated stuff with a partial and a block ... could someone take a look at this and maybe explain why my output is appearing out of order?
[01:52:52] Zinefer: https://stackoverflow.com/questions/45950682/ruby-partial-block-render-out-of-order
[01:56:59] Zinefer: i want to define a block and pass that into a different partial, and nest that blocks output inside html in the partial
[01:57:23] Zinefer: it almost appears like the block is rendering into the context which it was defined, rather than where it was called
[01:57:58] sevenseacat: thats not what youre trying to achieve, thats how youre trying to solve some mystery problem
[01:59:10] Zinefer: originally i had a partial file for each td element, because of a mess of other constraints on the class
[01:59:32] Zinefer: that was rather inefficient (taking 1-2ms per render call) so i was playing with this block
[02:00:42] Zinefer: actually, looks like this guy was having the same problem: https://stackoverflow.com/questions/8492349/rails-3-haml-block-passed-to-partial-rendered-in-original-context-instead-of-p?rq=1
[02:04:24] Zinefer: > Due to some Ruby quirks, if scope is a Binding or Proc object and a block is given, the evaluation context may not be quite what the user expects.
[08:45:30] dionysus69: I have a nested form and I want to not try create child object if it already exists, instead just create an association
[08:47:17] dionysus69: so this is how relationship looks https://gist.github.com/anonymous/9187364f19be07bf8cb05f1661312336
[08:48:08] dionysus69: and if tenant exists, just create evaluation and tenant_evaluation records, instead of give a validation error saying tenant already exists
[08:50:33] dionysus69: but perhaps there's no problem in that, I dont actually know why I created association like that. but would it be easier to solve my problem in that case?
[08:51:04] Sylario: dionysus : you need your complex version of the @something.build that is usually made in the edit action
[08:51:11] dminuoso: Yes. Or you have to stop relying on weird magical rails features and just use active record.
[08:53:07] dminuoso: sylario, instead of somehow relying on form builders construcing some.. magical object, passing it to some magical method and then expecting ActiveRecord to do "the right thing" I mean.
[08:58:34] dionysus69: evaluation accepts attributes for tenant, but if evaluation belongs to tenant, how can it accept_attributes_for
[08:59:27] Sylario: dminuoso: idk, the form builder is really designed with the way AR works, you can't really go very far without understanding that
[09:06:18] tbuehlmann_: dionysus69: I wrote an example application for what I guess is what you want (but having has_many and not has_one): https://github.com/tbuehlmann/has-many-through-selection
[09:08:52] dionysus69: tbuehlmann_: ok I got the main detail, if I pass id, it updates. but how can I prevent it to update either, just ignore attributes if one unique field matches
[09:09:47] dionysus69: so if it can't find id, it will create everything the usual way, but if child exists, just create the parent and set the FK
[09:24:26] dionysus69: but tenant may already exist, so I dont want to make tenant a primary form model, I want it to be created/not_updated based on if it already exists, while user creates evaluation
[09:36:11] Sylario: mm, I just inherited a 8 years old rails project, there i no gemfile, how do I know the rails version
[09:36:36] Sylario: mm, I just inherited a 8 years old rails project, there is no gemfile, how do I know the rails version
[09:38:06] Maakuth: is it running somewhere already? go to that box and carefully recover gem versions and ruby version from there and write yourself a Gemfile
[09:42:42] Knickelbach_: I just started learning ruby and have a question regarding something like capitalize! - Is there a practical reason why I'd use capitalize! instead of capitalize? Or is the ! operator mostly for convenience?
[09:44:32] tbuehlmann_: Knickelbach_: there are more than one intention when using bang methods. they can identity as a dangerous method, or, when having a non-bang version as well, as a mutating method
[09:45:03] Maakuth: sylario, uh oh, I don't think there's any way to know for sure then. I think I'd start by looking at version control timestamps to make educated guesses about versions
[09:45:32] tbuehlmann_: string.capitalize will return a new (capitalized) string object. string.capitalize! will return the same object, it being changed/mutated
[09:46:19] matthewd: sylario: There was a `config.gem` thing at one point... are there any lines like that, somewhere in config/ ?
[09:46:33] Maakuth: Knickelbach_, ! or ? in method name don't by themselves do anything though, they are just part of the name. convention for their use is like what tbuehlmann_ said
[11:01:06] Sylario: ok so the old lambda syntax is still valid for ruby, but in scopes it has a wrong behaviour, but the new syntax (->) works, so ruby is ok with old syntax but not rails?
[11:02:54] Knickelbach_: boolean_2 = !true && !true -- Codecademy says the value that boolean_2 holds is "false" but shouldn't it resort to "true" since the left and right side of the AND are both "!false"?
[11:04:21] Knickelbach_: yeah but wouldn't adding the && operator make it to "true" then? since both are the same?
[11:05:10] Knickelbach_: Ohhh, I thought adding && will compare both values and then set a true/false depending on that comparsion
[11:05:21] Sylario: Knickelbach_: http://4.bp.blogspot.com/-MX_uN_K_imI/UqzIQh7oOsI/AAAAAAAAAHo/HEgR6N6Qtfo/s1600/TruthTables.GIF
[11:06:02] Knickelbach_: I know how truth tables work, I was confused about the function of the && operator :)
[11:08:47] Sylario: worknick: rails do not care about html or js in a view, only thing ot recognise is a erb tag (in erb files)
[11:14:51] Sylario: worknick JS and ruby lives in very different place, by making them more cohesive you lose some separation of concerns