Page 1 of 5 | Next »
[16:17:22] tycoon177: is there a built-in way to load just the last association in a has_many in activerecord?
[16:37:48] tycoon177: thanks tubbo! I ended up just doing an `includes` with some conditions in the where clause that pared it down well enough that i'm not worried about performance impacts
[16:56:02] tycoon177: could someone help me understand why i'm getting a double render error with this? I am simply trying to serialize an array of hashes in my controller and responding with json data, but i'm getting a double render with this code: https://gist.github.com/BenMcH/aa43cbbd73e38deff0266bac0568bbe3
[16:57:17] tycoon177: i figured the block provided to the format.json would stop activecontroller from looking for a template file in my views, but this doesn't seem to be the case.
[14:37:18] tycoon177: good morning, i have a legacy table that i just converted to a rails-friendly naming convention and made it into a model, but the created_at and updated_at columns are not being properly updated. i'm not sure what is causing this, however. the db/schema.rb file appears to be correct. those columns are of type `t.datetime`
[14:40:41] tycoon177: oops, disregard. it looks like the updated_at did, in fact, just get updated. my bad
[14:38:09] tycoon177: does anyone here know how I could "group" 2 table rows in the Prawn pdf gem? Basically, if one of the rows is going to spill over to the next page, I need both of them to do so
[20:24:30] tycoon177: for anyone wondering the answer to my prawn question earlier, i ended up going through and making those rows a subtable. it's not pretty, but it keeps them together on the same page.
[15:03:27] tycoon177: is there a way to get rack-mini-profiler to work with sql server? i only see postgres and mysql mentioned in the readme, but we use sqlserver and have a route that is misbehaving
[22:00:06] tycoon177: if i wanted to have a link_to and include all of the params used on the current route, is there a built in way to do this? or am i stuck manually defining all of them? the use case that i have is linking off to a pdf view of the page for printing purposes
[22:00:21] tycoon177: and to generate the pdf, i need all of the same data to be passed to the controller
[19:40:52] tycoon177: hello, i am currently working on a sinatra app and was wondering what gems people are using to send emails from ruby since actionmailer isn't available without rails
[19:44:49] tycoon177: i did find this gem that seems like it'd be a good fit and isn't abandoned :p https://github.com/mikel/mail
[20:33:24] tycoon177: is there a way to get an activerecord #touch to also call after_save callbacks? i'd prefer to avoid having the two separate callbacks in case they were to change in the future
[20:40:56] tycoon177: it doesn't appear like that's possible in the docs...I'll just put some comments around these callbacks in our code to let anyone in the future know that they belong together
[13:00:47] tycoon177: Arkentias: activestorage requires a model, yes, but that's all that would be needed. i wouldn't roll your own solution with this being readily available
[13:01:05] tycoon177: there's no requirement for other associations on the model or anything like that
[13:03:15] tycoon177: you'll probably want has_one_attached https://edgeguides.rubyonrails.org/active_storage_overview.html#has-one-attached
[13:04:10] tycoon177: sorry to run, but i have to head to work. feel free to tag me in a message if you have any questions..i'll be back within an hour
[19:45:55] tycoon177: are there any good tools out there to reduce ruby's and rails' memory footprints or at least track down problem areas? our application consumes about 300mb/instance which is higher than we'd like.
[19:46:45] tycoon177: it's a very general question, i know, but this is something that won't have a one size fits all answer
[13:58:36] tycoon177: gavit: passenger and nginx or Apache is good (I prefer nginx) but we use puma in prod now and just proxy requests from nginx. I'd suggest sticking with passenger. We made this switch for ease of docker in production
[20:53:40] tycoon177: beingjohnm: you could have the forms submit to a nested route under the account, but i wouldn't worry too much about that as long as you run verifications that the user should be able to make those changes
[20:11:01] tycoon177: are there any options to write on pdfs with prawn? i see that they removed templates due to pdf corruptions
[20:36:34] tycoon177: because it can and will execute the same script multiple times in a browsing session, which, if you're not careful, can just keep attaching event handlers, for example
[19:30:58] tycoon177: can i specify a controller for a `member` block in routes.rb? i have a collection of non-restful routes that go together but shouldn't be methods on the parent controller
[15:17:04] tycoon177: i'm being very hopeful, but is there any way to graphically build pdfs with prawn?
[15:17:27] tycoon177: i have some reports that i'm needing to rewrite and put values in very specific places on top of an image
[15:17:54] tycoon177: if not, i'll have to print it out and draw a grid on it to get at least rough ideas for pdf units :p
[16:27:08] tycoon177: felix_vs: check out rvm. if you install ruby, you can then install rails with the built in `gem` command (or from a Gemfile)
[16:32:38] tycoon177: felix_vs: you're able to set a default ruby version and then a local version if it differs from your default
[18:19:29] tycoon177: a Gemfile is a file that outlines what gems (ruby packages) a project uses. When you generate a new rails application, this is automatically generated.
[18:20:13] tycoon177: Using this file (or a Gemfile.lock, after the initial dependency resolution) bundler (a gem itself) will automatically manage your project's dependencies
[18:30:22] tycoon177: i'm not sure how it's best used with existing applications, but you should be able to do that, yes
[20:34:29] tycoon177: plus, delayed jobs are run in a separate process to rails, so that'd make it INSANELY hard to test
[21:09:25] tycoon177: Vashy: you'd store any related information in the model that it's attached to.
[21:12:18] tycoon177: i'm not familiar with how active_storage works atm, i assumed that it just stored a path in the model, but that doesn't appear to be the case
[21:16:00] tycoon177: has_many_attached seems like it'd cause nothing but headaches if you wanted to store metadata in the db
[21:36:28] tycoon177: Vashy: this video (although quite old at this point) will help with nested form creation
[21:30:02] tycoon177: what templating engines out there are worth looking into? erb is really starting to grind my gears. i'm going to be looking into haml. it's the one i see most often, next to erb. Are there any others worth looking into?
[15:50:16] tycoon177: is there a way that i can convert a symbol to a string without the colon being included in the string?
[15:52:36] tycoon177: Celmor: you could look into Pandoc bindings. i'm sure that pandoc could handle markdown to pdf
[16:02:27] tycoon177: disregard my question re: symbols. it seems like that's not the standard behavior if i just run irb, so i think this is a rails specific thing (or project specific)
[16:08:49] tycoon177: i'm fairly sure that `resources :probations` would be required here. AFAIK, `resources` is always expecting a plural name
[18:58:25] tycoon177: syndikate: why wouldn't it change the paths? it's a completely different resource :)
[20:50:21] tycoon177: is there a way to create a has_many association on multiple foreign keys? right now, i have a method named after the association that just calls to the other model directly, but this stops me from using the association in `includes` or `joins` and has been causing n+1 queries out that wazoo
[21:17:17] tycoon177: desnudopenguino: no, sorry, i didn't explain it well. The two tables should be connected via 3 of their columns. the rows only match if all 3 values match. it's a strange, strange setup, i know, but it was well in place before i got here :p
[21:17:49] tycoon177: desnudopenguino: i think i'll end up just joining on a different table and then use #select or #keep_if on the ruby end of things
[21:24:59] tycoon177: mlt-: when you say raw sql, how do you manage this in rails? can you set the join syntax when setting a has_many or a belongs_to? i'd be happy to do that, but i don't think i'll use that gem
[21:26:19] tycoon177: how would i be able to do this join (or includes) with raw sql if wanted to use the model in rails too?
[21:27:27] tycoon177: it's fine, i'll just join on another table that's already in the query and then filter my results with #select
[21:29:22] tycoon177: thanks for taking another look! i was hoping that i was overlooking something in the docs, but this is a very odd thing to have to do, i'll admit
[21:29:56] tycoon177: i can very easily think of a better schema that would've fixed this, but technical debt is preventing such a migration
[14:23:48] tycoon177: konsolebox: N is used to indicate a number, which could be variable, i'm pretty sure.
[20:50:07] tycoon177: i haven't found one, but it'd be nice to be able to drag instead of working in inches and such
[22:19:34] tycoon177: That's not a bad idea Inside. I'll give that a shot next time I build a report.
[18:32:15] tycoon177: dcopie: to make sure i understand, you want 100% of the subdomain traffic to go to a single route?
[19:41:23] tycoon177: i am trying to contribute to an open source gem but am having troubles figuring out how to get an actual stack trace from minitest. The gem interfaces with activerecord and simply reports that there was an error and gives me the location of the original test in activerecord's test suite, but it doesn't give me any more code locations to check (like where the actual exception happened, for example)
[19:41:38] tycoon177: is there any way to have minitest output a full stack trace when there's an error that occurs?
[20:06:36] tycoon177: zenspider: here you go! I'm trying to help update a mssql adapter to rails 5.2 and this just isn't giving me the output that i need to track down these bugs :p https://gist.github.com/BenMcH/fb2bd18ccef112fc0320014966d494dc
[20:09:28] tycoon177: sorry it's not the full test suite. there's a lot of them and one of the tests causes the whole suite to hang
[20:36:23] tycoon177: zenspider: i was able to find that setting `BACKTRACE=yes` (anything not null, i think) in my environment, minitest is now outputting full stack traces for me :)
[20:48:59] tycoon177: no worries! irc is async :p that's all that would be shown for each error unless i set the BACKTRACE env variable
[21:13:40] tycoon177: zenspider: it may seem silly, but that's the desired behavior in this case (seeing exceptions as they're thrown) because my test suite never finishes due to a weird test that uses 2 nested forks in the activerecord codebase
[21:23:23] tycoon177: zenspider: nah, i've identified the test, but not why it's failing on rails 5.2. right now, i'm just trying to update a gem to help out the maintainer since our company uses his gem in every single project
[21:37:06] tycoon177: but there needs to be some way for the server to relay that information to the client
[21:49:18] tycoon177: timdotrb: if you find one, let me know please! i searched and searched but couldn't find one. i ended up having to piece together how to write a rake middleware
[18:54:36] tycoon177: where can i effectively learn OO ruby? I have been working with rails for over 2 years now and i have learned a lot (i think) of ruby, but i stumble greatly when it comes to modules vs classes and things like that
[19:45:43] tycoon177: i cannot figure this out...i'm trying to define a new route inside a namespace (which i've done many times before) and i keep getting `uninitialized constant Reports::Controller::Controller` where reports is the namespace and controller is my controller name
[19:47:26] tycoon177: and my controller is defined as `class Reports::SomeController < ApplicationController`
[19:48:19] tycoon177: aaaaand disregard. I was trying to access the model under the controller's name in the index method
[15:31:10] tycoon177: is it bad practice to have a non db-based model? Like, I have some static data that I'd like a model for because it's used across several models and didn't know if it'd be best to just make a PORO or if there's some other way to do this
[16:33:46] tycoon177: NL3limin4t0r: thanks for the input. I ended up just writing a standard class that doesn't inherit from activerecord::base and ended up just writing a few helper methods to get the right instance. In the end, it creates a maximum of 3 (at this time) objects in memory with 2 attributes each. It just started to get a bit messy with magic numbers flying around due to some legacy code
[20:52:34] tycoon177: has anyone here run into issues unzipping a zip file created with rubyzip on a mac? the files are unzipped just fine when using `unzip` from the terminal, but simply double clicking on them to open them with archiveutility fails with "Error 1 - Operation not permitted" (and this is only sometimes)
[20:52:50] tycoon177: I haven't found a common factor with the files themselves, but this has been driving me nuts
[20:53:28] tycoon177: because the fix thusfar has been to have marketing (who uses these zip files) send the files to me where i unzip and rezip the files manually
[20:59:10] tycoon177: elomatreb: I agree, but I feel like there should be a way for this to be corrected :/ oh well, I'll just continue to deal with it I suppose
[21:14:09] tycoon177: elomatreb: i just got a response in ##mac and it turns out the issue *is* with the OS. OSx uses bsdtar under the hood whereas most linux distros use gnutar
[21:22:15] tycoon177: I just switched from using the built in archive utility to using "The Unarchiver" and it fixed the issue
[13:35:02] tycoon177: My use case is this: All requests when a user is not signed in are automatically redirected back to a login form. We just recently pulled this code out into a reusable gem and transformed it into a Rack middleware vs doing this in a before_action. Now, all of my tests are passing except for the tests that redirect a user back to login. The middleware is mounted, but it's not ever called when doing controller specs
[13:37:13] tycoon177: I'll have to figure out how to make these controller specs into request specs or something like that
[13:37:35] tycoon177: Some of our apps would be able to use system specs, but others are stuck on rails 3 (but we're working on that too)
[13:38:50] tycoon177: we haven't used any request specs in this app, so i'm not super familiar. It'd just be spec/requests instead of spec/controllers, right?
[13:53:54] tycoon177: tbuehlmann: thanks again! My specs are working when changing it to a request spec :)
[19:08:54] tycoon177: nzst: thanks :) i was actually looking at the jquery-rails gem because the asset pipeline page on edgeguides.rubyonrails.com said that it was a good example
[19:46:10] tycoon177: nzst: no i didn't :( I had to read a few gems' source code to figure it out myself. Once I get a better grasp on it, i'm considering writing a blog post about it. it was pretty painful finding out how to write custom rack middleware, tbqh
[19:48:01] tycoon177: nzst: that being said, I know rack middleware outside of a gem, in a folder like app/middleware is all of the benefit, none of the headache of bundling it with a gem. The hardest part about the gem was having it auto mount the middleware when the gem was included in the gemfile
[19:55:37] tycoon177: nzst: this is the only thing I was able to find that explained it enough https://stackoverflow.com/a/5730274
[20:21:22] tycoon177: nzst: you technically *could* use a middleware for this, but there's nothing stopping you from using a catchall route and a table in your db for redirect mapping
[20:21:44] tycoon177: nzst: i did something similar in another app at work. Let me find some code for you to reference
[20:24:59] tycoon177: nzst: https://gist.github.com/BenMcH/44c78c2270f88d5ce00cf134b42b77a6 Here's the general idea behind my idea. You *could* do this right in your rails routes once and then manage the redirects at the db level. If you truly don't want to handle this in rails, you *can* write a middleware and it'd respond slightly faster, but then you have to deal with supporting that middleware
[20:27:33] tycoon177: nzst: we use 2 of those in a single application to manage both a cms style of content filled pages and to handle category names or ids in the url. It works well for our uses, but we're pretty low traffic, so ymmv
[20:28:17] tycoon177: you might want to change `/:id` to `/:slug` in your case. Then you would be able to access it in the controller or view via `params[:slug]`
[20:36:43] tycoon177: hahuang65: if everything is the same, i believe rails just does a begin and commit transaction
[21:39:47] tycoon177: if i'm understanding correctly, you'll want an index on your users.office_id column
[22:22:49] tycoon177: fox_mulder_cp: good to know! Thanks :) I usually forget that I can do an association like that in a migration
[19:03:52] tycoon177: Is there a way to access the rails cookies from rack middleware? I want to rewrite a before_action callback in my application controller to a rack middleware.
[20:03:15] tycoon177: I found the answer to my question. In case anyone is wondering, you can recreate a request object in rack by calling `request = Rack::Request.new(env)` in the call method of the rack middleware. After this, you can access your session variables by calling `request.session[:session_var]`
[20:03:40] tycoon177: It's not 100% the same as the rails request object, i don't think, but it's close enough to get and set session variables :)
[13:04:08] tycoon177: it feels so good to have rewritten a report that was ugly code and made it beautiful
[16:03:31] tycoon177: I am having issues with rubyzip in my rails application. Sometimes, the zip files that are generated cannot be opened on osx, with an error of operation not permitted. I found this relevant issue on github https://github.com/rubyzip/rubyzip/issues/249. I was wondering if anyone else has run into this issue or if there is another library that I can use to zip these files in rails
[16:04:01] tycoon177: the files that I am zipping, in case it matters, are all photos. There are generally 15-25 of them
[18:21:53] tycoon177: I am having issues with rubyzip in my rails application. Sometimes, the zip files that are generated cannot be opened on osx, with an error of operation not permitted. I found this relevant issue on github https://github.com/rubyzip/rubyzip/issues/249. I was wondering if anyone else has run into this issue or if there is another library that I can use to zip these files in rails?
[19:04:52] tycoon177: does anyone here know of an alternative gem to rubyzip? we've been running into the same issue outlined here https://github.com/rubyzip/rubyzip/issues/249. Basically, *sometimes* the zip files generated by rubyzip can't be opened by the default archive utility on osx. I checked and all of the file names are unique. That was mentioned as a possible cause on that issue thread
[19:08:55] tycoon177: gizmore: i might look into doing that. Thanks! I was just wanting to make sure that I wasn't just missing another gem. I tried searching but didn't find anything
[20:10:25] tycoon177: fwiw, i would also suggest rebuilding on a new rails version. we have a rails 3 application at work that we've been trying to get up to rails 5 for some time now..it's hard to both add features and work on upgrading the underlying rails version at the same time
[16:55:44] tycoon177: I'm looking at some old code I wrote for a report and I'm cringing whilst reading it...I need to rewrite this. It's like I didn't know that .map exists
[13:58:50] tycoon177: It appears that my rails app is saving datetime objects to the database in UTC time. Is there a way that I can correct this and/or fetch them under the correct time?
[14:47:09] tycoon177: sorry, i was pulled away from my desk. What would I do in rails to convert it to the correct time before serving it up? Just date.with_timezone?