#RubyOnRails - 03 May 2018
« Back 1 day Forward 1 day »
[00:23:31] amperry: hi folks, got a question. It looks like, with cocoon, you can't transitively add an association through belongs_to -> has_many. In more concrete terms, my model, Lease belongs_to the model Placement, which has_many MonthlyCharges. I'm trying to use cocoon's link_to_add_association to add one or more MonthlyCharges to the Lease. gist here: https://gist.github.com/amp108/b18acf50ac9395af19324aac55c49257
[00:24:17] amperry: seems like you maybe can't do that, but I'm wondering what my options might be at this point.
[10:05:21] dminuoso: So. The most amazing thing Ive started is passing parameters explicitly from controllers into views.
[10:05:36] dminuoso: This de-facto global shenanigans with assigning to ivars is the worst idea about rails.
[10:55:44] Radar: dminuoso: is now the time to mention that hanami does this through action exposures? http://hanamirb.org/guides/1.0/actions/exposures/
[12:59:13] sevenseacat: I would also much prefer to explicitly assign variables to views, its one of the things that surprised me coming to Rails
[13:29:42] dminuoso: sevenseacat: You can do it. The rails documentations just do their best to keep it a secret.
[13:41:13] mrbubbles: Hey folks, I was just hoping someone can advise on using accepts_nested_attributes_for. Here is a minimal recreation of my issue: https://gist.github.com/joeczucha/26b25bf65f74c34f613c2667c7d84503
[13:41:52] mrbubbles: Basically A and C are joined through join model B. I want to create a new C and at the same time create a join record B, with a couple of attributes
[13:42:40] mrbubbles: But when I use accepts_nested_attributes_for C is able to create B but doesn't include the ID of A so it fails
[14:54:54] jammanbo: Is this a bad idea. A controller action might take some time, or it might not. I was going to try and put the slow running stuff in an async ActiveJob, but somehow wait a few seconds within the controller to see if the job finishes. If it does, send one response, if it doesn't, send another. Rails 4 so ActionCable isn't a ready alternative.
[16:54:31] conceivably: Hi. What do people use to generate pdfs from HTML views these days? Wicked PDF's backend doesn't properly support modern CSS due to an ancient webkit version.
[17:30:56] blackcross: I have a "def get_cache_ndc" in line_items_controller.rb, how would I include this in another controller? namely, "home_controller.rb"
[17:31:46] tbuehlmann: blackcross: you could define it in a module and include it in both controllers. you could also define it on a shared parent controller
[17:36:36] blackcross: it queries a model, @line_item = line_item.find_by(drug_code: CODE) and if it finds it, returns @line_item, if not, it queues 10 other models, and copies all those attributes into a @line_item.new, then returns @line_item
[17:38:42] blackcross: so how would i just include that 1 "def get_cache_ndc" into another controller? I tried require get_cache_ndc and require line_item_controller, and include line_item_controller and include get_cache_ndc, but none work
[17:39:09] blackcross: i am pretty sure this is just basic ruby i am asking about, but even google doesn't have documentation on how to directly include 1 definition
[17:42:11] blackcross: looks like i can do "require line_items_controller.rb", but this makes all the definitions accessible, which i do not want
[17:46:43] tbuehlmann: so, this is one way: https://gist.github.com/tbuehlmann/907617d1b0cef102a52ac071be2c52ec
[17:49:00] tbuehlmann: another option: https://gist.github.com/tbuehlmann/1d601c9a2c6bc812e6771b31ae06befa
[17:49:23] tbuehlmann: with that the cache_ndc method would be available in each controller that inherits from ApplicationController. that might be too much though
[18:24:10] Inside: So - something weird happened. I upgraded to rails 4.2 (yaaay) and then the production environment refused to start up because I had an invalid validation (was calling "validate :name_of_attributes" instead of validates: ).
[19:11:19] Inside: (I was stuck at 4.1 because we were running sql server 2005 for the longest time and sql-adapter-4.2+ doesn't support it -- finally we moved to 2014 or something)
[21:19:00] openstruct: I've been building a lot of dashboards recently that manage multiple resources and have been wrestling with the best way to handle CRUD actions. For example, given a product dashboard that manages cameras, lens, and tripods, should the ProductDashboardController handle the CRUD operations or should the individual resource controllers handle those? It seems like the individual resource controllers should be responsible instead
[21:35:24] openstruct: Yeah, that's what I feel like it's most appropriate to have the dashboard forms call to their respective endpoints.
[21:45:56] cagomez: +1 for individual resources. at the expense of more files, the controllers will be easy to reason about and test
[22:03:43] Radar: A controller that has hundreds of lines in it to manage > 1 resource is a prime target for a good ol' refactoring.
[22:05:05] Radar: But no, #realtalk time, I only _need_ two actions in my app: https://github.com/radar/twist-v2/tree/master/backend/apps/web/controllers
[22:10:04] openstruct: The only part that feels hairy to me is handling redirects and errors, but that's just because the front-end of this app isn't fleshed out to handle those. I think once I get it nailed down, it should be pretty easy to write dashboards on dashboards on dashboards.
[22:25:30] Radar: Those are the beautiful mask that hides the absolutely atrocious Markdown sins I am committing elsewhere.
[23:21:06] Intii: Hey all, I have a query that runs inside ActiveRecord.transaction do to do a rollback in case something fails. In that block I update a column in the user's table that shouldn't rollback regardless of the fail or not. Is there anyway to achieve that?