Page 1 of 1
[21:21:48] sunya7a_: hi, I have a many to many relationship (between model A and B with joining model AB) and would like to create a nested form for A that will accept values for B. When B already exists I would like to create the record in the join table without creating an additional B record. When B does not exist it should be created and the corresponding AB record as well. This is similar to this question on SO https://stackoverflow.com/questions/43106241/obj
[21:22:48] sunya7a_: it feels like this is a common use case but I don't know what to call it and that is the closest I've found. If there is a name for this could you tell me so I can research it on my own further
[05:19:24] sunya7a_: hi, I have a call back (after_create) that is meant to create some additional resources but for reasons beyond me it is firing twice. anyone know why this might happen? https://gist.github.com/anonymous/06e67b1226850531f72b25df719c6ecf
[05:35:59] sunya7a_: dminuoso: I'm trying to step through the code...the first time my measure resource is added is during my loop...as I step through further rails is calling something inside active_support/callbacks.rb, during which measure i see active record insert the measures again. Is that what you are referring to, that autoloading being screwed up? Could you tell me why that happens or give me some resource to read up on this?
[05:36:57] sunya7a_: dminuoso: I'm not sure i understand what you mean with I "shouldn't already notice it". you mean this problem would have manifested itself somewhere else already?
[05:37:42] sunya7a_: dminuoso: i believe this is the first time I see it happen. I use after_create quite frequently in other models...only this time it's behaving this way
[06:45:37] sunya7a_: dminuoso: so I printed the backtrace and it is indeed being called twice...i don't understand why.
[06:45:59] sunya7a_: dminuoso: the fix is to go about creating the resource in the join resource...instead of the measure
[06:46:29] sunya7a_: dminuoso: https://gist.github.com/anonymous/9d0e3e640a370fb0afe3073bd5710978 the top version works...the bottom doesn't....could you help me understand this...is it a rails bug?
[06:59:50] sunya7a_: dminuoso: okay ... i did that...stopped rails server...stopped spring...placed bybug inside the class just below class ResultStatisticSection < ApplicationRecord line...then triggered the situation...i was dropped into debug mode once...pressed c to continue...didn't drop into debug mode again...rails created twice the record i expected. were you expecting it to drop into debug mode twice, thus explaining the double laoding?
[07:16:15] sunya7a_: dminuoso: here's a print out of inspecting ResultStatisticSection._save_callbacks, I grep'ed through the app and found the class defined only once (also in gist). Furthermore, it doesn't actually seem like the after_create is called twice, instead after_create is called once...then it goes through the loop of my method to add the measures and when it finishes it goes back into active_support/callbacks.rb:456 and runs whatever is inside @after
[07:17:27] sunya7a_: dminuoso: please have a look at my comments in def create_default_descriptive_statistics . doing it one way creates double records...the otherway does it correctly. i'm just not sure why
[07:18:55] sunya7a_: dminuoso: i'm sorry...i should have inspected after I declared the callback...let me update the gist
[07:20:00] sunya7a_: dminuoso: only the p ResultStatisticSection._save_callbacks is different in this gist...the rest is the same
[07:39:16] sunya7a_: dminuoso: https://gist.github.com/anonymous/a7799ed88223687dcc72c78110383ec7 this is with measure.rb
[07:45:57] sunya7a_: dminuoso: as ExtractionsExtractionFormsProjectsSectionsType1RowColumn is created I create 4 default ResultStatisticSection. This in turn checks its type and if it matches the first type it iterates through measures and adds the default ones as well. I alias that long class name to subgroup.
[08:02:33] sunya7a_: dminuoso: so what i'm trying to accomplish is add default measures to a specific type of ResultStatisticSection. ResultStatisticSection has many-to-many relationship with Measure via a join model. A ResultStatisticSection is created when ExtractionsExtractionFormsProjectsSectionsType1RowColumn (aka subgroup) is created via after_create callback
[08:07:06] sunya7a_: I am making an update to another resource called ExtractionsExtractionFormsProjectsSections
[08:11:05] sunya7a_: dminuoso: idk exactly which line causes the bad behavior...in my opinion it should work...line 24 in result_statistic_section.rb does exactly what I want it to...but then once that method is called rails goes back into active_support/callback.rb and triggers the insert a second time and I don't know why it does that...but somehow when I create the join resource instead of doing measures << m on that same line it doesn't insert twice
[08:11:40] sunya7a_: 'once that method is called' meaning once it's done...it goes into callback.rb and does the insert again
[08:12:44] sunya7a_: dminuoso: that should be line 11: @extractions_extraction_forms_projects_section.update(extractions_extraction_forms_projects_section_params)
[10:20:06] sunya7a_: dminuoso: ok...i created a test case...but the only thing i was able to do was reproduce the issue with the test...I decided to try something else...created a new app to show case the problem...i think this is rails behavior and it is either working as intended or a bug: https://github.com/sunya7a/rails-bug
[14:57:38] sunya7a_: NL3limin4t0r: thanks...i believe what i was looking for doesn't exist...what i wanted was for the nested resource to do on: :collection but with the option to not include the parent...I'm already using shallow nesting...but that's not the issue....I simply created a level one resource (one without being nested under a parent) and used on: :collection
[13:40:12] sunya7a_: I have a nested resource and wish to define a custom action on a child collection. Rails is automatically adding the parent and parent id in to the url...how do i prevent this besides redefininig the resource without the nesting...is there an option with on: :collection?
[16:56:07] sunya7a_: NL3limin4t0r: My understanding with shallow nesting is that it will not use the parent if it isn't necessary for the default actions. It doesn't seem to work for custom actions though...it still shows the parent resource in the url
[12:01:40] sunya7a_: in a many-to-many relationship what is the cleanest way (built-in) to prevent duplicate entries when using nested forms? So for example...given model A and B, if i update A and have the option to add a new B via nested fields, I would like to connect to an existing B and only create if there is none
[12:11:25] sunya7a_: I believe there might not be a build-in way...what I would like to discuss is the cleanest way of accomplishing this...i.e. when it's best to check for an existing record
[07:39:32] sunya7a_: hi all, I have a form with nested fields. while populating the elements in the nested fields I use label_method. problem is that i run into n+1 problem regardless of using .includes. Could someone point me to a resource that discusses this problem or is there no workaround?
[07:57:50] sunya7a_: sevenseacat: here is the view and controller: https://gist.github.com/anonymous/798f6c05820740684fa16ccabd8e914b
[07:58:36] sunya7a_: sevenseacat: I believe the relevant line is line 4 in the controller. The n+1 issue arises because it's fetching the profile username information one at a time even though I'm including it (or so i think)
[08:00:38] sunya7a_: sevenseacat: yup...this is a silly question, but i don't know how to edit a gist. should i just createa new one?
[08:01:58] sunya7a_: sevenseacat: https://gist.github.com/anonymous/764f763306a0517316217bfc56bce1b0
[08:04:10] sunya7a_: sevenseacat: hm..there's no view associated with profile in this controller action. the information it's trying to fetch is populating the dropdown...line 10 in the form
[08:05:45] sunya7a_: i'm calling label_method: :titleize_username. which is a method in User model: https://gist.github.com/anonymous/8cba0c0a189d7a42799fd1e17b899f4d
[08:07:36] sunya7a_: sevenseacat: ahh...sorry about that.....i did attempt to call includes in the User model...but that diesn't seem to work
[08:13:13] sunya7a_: sevenseacat: problem persists: https://gist.github.com/anonymous/4cdca68efcfa7d7bc63b34fd6696c413
[08:14:23] sunya7a_: sevenseacat: i am....i will take out the set_project for edit action and place the code in set_project directly in edit
[08:15:56] sunya7a_: sevenseacat: yea same: https://gist.github.com/anonymous/aceb0ec0190b18c76519e302109e5be2
[08:17:58] sunya7a_: sevenseacat: https://gist.github.com/anonymous/4648d3fcd034b4537e4b6907d27049ba
[08:22:14] sunya7a_: sevenseacat: https://gist.github.com/anonymous/c73307b51a47d7c30db76a80f7c97e97
[08:28:43] sunya7a_: sevenseacat: hm....i see...i don't suppose i can pass an empty object with includes....that doesn't really makes sense
[08:29:50] sunya7a_: sevenseacat: but...hm...that doesn't make sense though...if I count the number of n+1's i see a total of four
[08:30:15] sunya7a_: sevenseacat: I assume for the three assignments that already exist and being rendered and one more for the empty partial
[08:34:02] sunya7a_: i was afraid I misunderstood how includes works...and that was a bigger issue to me
[08:43:19] sunya7a_: I have 3 models: A has many B and B has many C. I'm using delegate to get from C to A. Given a collection proxy of C's how can I get the corresponding A's? I've tried using delegate in the B model to help bridge from C to A, but it doesn't do what I expect it to
[05:25:41] sunya7a_: could someone suggest a good way to deal with join table names that are too long? I've been staying very consistent with my naming convention up until now but I've come to a point where the name is over 64 characters long
[13:58:22] sunya7a_: composite keys in activerecord. I only find composite_primary_keys gem....is there a native solution in place...or any plans for one in the works?
[14:14:30] sunya7a_: workmad3: okay...so the gem is pretty much what people use? or just kind of manually manage is better? (in your opinion.)
[16:24:27] sunya7a_: composite keys in activerecord. I only find composite_primary_keys gem....is there a native solution in place...or any plans for one in the works?
[19:52:04] sunya7a_: using ruby 3.02 and I'm trying to add a custom data attribute to an image_tag helper...Could someone tell me why I'm not getting what I expected: https://gist.github.com/anonymous/57a13133ef81634b4694
[19:53:21] sunya7a_: according to this the data attribute should be formatted the way I wanted http://stackoverflow.com/questions/20152927/how-to-add-jquery-data-attributes-in-rails-image-tag
[20:43:49] sunya7a_: hello. I have a general/best practice question. If I was to share my rails application with another group or let's say put it up on github (public) what is the best practice in terms of handling configuration files, for example the database.yml file or any other file that may contain 'sensitive' or my installation specific information?
[20:44:53] sunya7a_: my first instinct is to replace the database.yml file with a symlink and point it to the file somewhere outside the repo