#RubyOnRails - 19 April 2018
« Back 1 day Forward 1 day »
[06:14:02] dionysus69: how would I pass raise error message back to controller and show it to user with redirect_to notice?
[06:25:24] timdotrb: I have an active job which sends off a mailer. When I call perform_later, it fails to pass variables from the mailer to the mailer’s view. If I call perform_now, everything succeeds
[06:37:34] timdotrb: Radar: have you ever run into such an issue? Where perform_later acts differently than perform_now ?
[06:37:47] Radar: But I want to confirm your Gist is the same problem before I go giving away information that is wrong.
[06:38:03] Radar: "Better to keep your mouth and let people think you're an idiot than to open it and remove all doubt" and all that
[06:43:47] Radar: https://gist.github.com/willc0de4food/92d061fa089bd1d41dc251225938ae24#file-flyer_campaign_job-rb-L7
[06:45:10] timdotrb: Radar: makes me curious as to how it was working, lol. I previously had a bunch of logging and nil checking, but none of it seemed to be working
[06:48:28] dminuoso: timdotrb: On an unrelated note: if you have something ERRENOUS, dont log it with info..
[06:49:46] Radar: timdotrb: I am not sure then what could be going wrong. It looks fine to me. I would probably need to toy around with the application locally to figure this one out.
[06:50:36] timdotrb: Radar: is there any reason why calling .perform_now would be bad vs perform_later ?
[06:51:53] Radar: Some way of having this problem happen on my machine would mean that I could investigate and probably fix it
[06:53:00] timdotrb: Radar: the worst part is, it works locally for me. The problem only occurs on my production server
[06:53:26] Radar: https://gist.github.com/willc0de4food/92d061fa089bd1d41dc251225938ae24#file-flyer_mailer-rb-L7
[06:55:27] Radar: Ok. and then attachments['flyer.jpg'].url should probably return a URL... relative... I am not sure what it returns.
[06:57:41] timdotrb: I don’t see a way in the Mail app to view the original content of the email that was sent..
[06:59:06] Radar: https://gist.github.com/willc0de4food/e8364a7198617699f53c230d1fb2a84d#file-email-L147-L155
[06:59:23] Radar: Right, so the image is there... but I don't know what attachments['flyer.jpg'] is supposed to do
[07:00:12] timdotrb: Radar: https://stackoverflow.com/questions/4918414/what-is-the-right-way-to-embed-image-into-email-using-rails
[07:01:01] dminuoso: timdotrb: Please reduce to a testcase. Reduce all that stupid noise from your job, remove the view.
[07:01:42] timdotrb: dminuoso: this was the test case I made: https://gist.github.com/willc0de4food/8aeac6cb20c35f82df181ac25d6af8d6
[07:07:43] dminuoso: timdotrb: Please also remove extra log statements that are irrelevant to your problem.
[07:08:41] dminuoso: timdotrb: And also show us your Flyer model, as well as the controller code that somehow feeds flyers with images.
[07:19:53] timdotrb: I’m actually getting a new error in this test case. It’s failing at the url_for
[07:22:56] timdotrb: https://gist.github.com/willc0de4food/8817683bc3e9ad6a83aaeeb77a2918c3#file-flyer_test_job-rb-L14
[07:25:37] timdotrb: dminuoso: Lol yea, the flyer model isn’t something you really want to sift through >.<
[07:34:54] dminuoso: timdotrb: Anyway. The point of a testcase is to not reduce beyond changing behavior.
[07:35:39] tbuehlmann: oh I see, you include Rails.application.routes.url_helpers, that's why you want that method
[07:36:53] tbuehlmann: I have some "why do you"s, but I guess this will not lead to solving your problem
[07:38:25] dminuoso: timdotrb: At any rate: I suspect that the pwd is different if you perform later.
[07:38:31] tbuehlmann: maybe one, though: why do you create these links in the job and not in the mailer or even the mailer view?
[07:38:58] dminuoso: timdotrb: If you just took a look at what attachments held you would see the problem.
[07:39:45] timdotrb: tbuehlmann: I was attempting to generate the URLs in the mailer views, but was running into the same issue; flyer.guid or list_agent.guid was nil
[07:40:21] timdotrb: I had a hypothesis that for some reason, some variable(s) weren’t making it to the mailer view
[07:41:36] dminuoso: timdotrb: https://gist.github.com/willc0de4food/8817683bc3e9ad6a83aaeeb77a2918c3#file-flyer_mailer-rb-L5
[07:47:16] timdotrb: dminuoso: https://gist.github.com/willc0de4food/c139098b28b55a4d42ed3466c21d80d6
[07:53:01] dminuoso: timdotrb: I dont know what to tell you. The default_url_options appear to be nil.
[07:53:23] dminuoso: timdotrb: https://gist.github.com/willc0de4food/c139098b28b55a4d42ed3466c21d80d6#file-flyer_test_job-rb-L21-L23
[07:54:00] timdotrb: dminuoso: I read that as of Rails.. v4? For custom application config variables, you have to use Rails.configuration.x.name_of_var
[07:59:08] timdotrb: dminuoso: I’ve had that variable set this entire time. I’ve done a touch tmp/restart.txt, service nginx restart and god restart resque
[08:07:03] dminuoso: timdotrb: hop into a pry shell in that spot, and poke around. how does Rails.configuration look?
[08:14:25] timdotrb: dminuoso: https://gist.github.com/willc0de4food/6796a9f8fbcf9506e4f12c917a84628b
[08:15:00] timdotrb: dminuoso: I don’t see the custom application config variable that I created in there
[08:19:19] timdotrb: dminuoso: the weird part is, if the variable was undefined, I would’ve gotten such an error. I didn’t, I simply got nil. So the variable is defined, it’s just nil.
[08:21:02] dminuoso: timdotrb: Rails.configuration.x.anything.blah at least is guaranteed to be nil.
[08:22:38] timdotrb: Presently, this is the command I am executing: git pull origin testcase && touch tmp/restart.txt && sudo service nginx restart && god restart resque
[08:25:22] timdotrb: dminuoso: https://gist.github.com/willc0de4food/92c10d595b4d8402133ea5a5e1c59cb1
[08:26:17] dminuoso: 10:24 timdotrb | I just told god to stop resque, but I still have 0 of 2 workers working..
[08:26:49] timdotrb: https://www.dropbox.com/s/rupp8a55wkdzdox/Screenshot%202018-04-19%2001.26.45.png?dl=0
[08:36:32] dminuoso: But if `god` doesnt do its things, then its not surprising that things dont work if `resque` cant get restarted
[09:06:57] timdotrb: dminuoso: I had to do a gem install on a couple different gems that were reported as missing in my resque_error.log, it’s now working. It seemed as though I had some old resque process running that was just hanging out or something
[10:25:05] dminuoso: Radar: Once the testcase was produced it became obvious that the default_url_options that were introduced were not picked up.
[10:56:42] dminuoso: If I have a has_many onto itself, how can I get another has_many through that relationship? https://gist.github.com/dminuoso/6e4676eba7ebf23768fd7213c6cb1a34
[11:19:16] randohinn: Just made this Rake task for my application, only to discover migrate is not a method anymore... What's the easy fix here? https://paste.ubuntu.com/p/Yb26mNSFx8/
[13:21:31] Andr3as: anyone ever tried to use Roo to parse csv / xlsx files? i have a text file which essentially is a tab delimited csv but with a txt extension.. i though this should still work but roo throws me an error "key not found: :txt"
[14:58:46] mauro1254: Hi folks, I need to have certain data manageable/available from/to a dozen of apps. What dou you think about having a Rails API app and a mountable engine, is there an easier way to achieve that?
[15:01:59] dminuoso: Say some IPC mechanism. Maybe some plain simple serialization over unix domain sockets..
[15:04:53] mauro1254: dminuoso : data consists in entities (models) that I want to be available to all applications and that can be associated to application specific models.
[15:05:35] dminuoso: mauro1254: Oh actually I misread that. That small rails API+mountable engine sounds fine.
[15:06:21] dminuoso: mauro1254: I personally wouldn't go for an entire engine though. A simple library likely is enough.
[15:07:02] mauro1254: dminuoso : with a mountable engine I can manage (CRUD) entities in each application
[15:08:56] mauro1254: dminuoso : the fact is that I don't want to build the view layer ao dozen of times (forms for creation/editing, ecc)
[15:09:51] dminuoso: mauro1254: When you say "manageable", do you mean from a developer or from a user point of view?
[16:29:26] pushcx: Is there a way to add to a scope's select clause rather than replace it? scope.select('foo as bar') without having to say .select('model.*, foo as bar')?
[16:50:41] Inside: Heyo! I'm using activemodel's store functionality. The attributes used by the store are in an array.
[16:51:13] Inside: I've tried calling permit() multiple times, but apparently it only likes the last call.
[16:58:01] Inside: ahhh I think it does work calling it with an array - I just have an error past that
[17:00:02] Inside: yup yup.. I moved from an after_save callback to a before_save callback and something's causing recursion until the stack blows :|
[17:15:25] Inside: moving from a before_save with a check for new_record? to after_create fixed it \o/
[18:16:31] dgsan: mroutis: Thansk, I didn't see your message 'til today. I guess I have a version issue.
[18:28:02] Trevoke`: Hey all, I lost track of how `Integer("5")` is implemented in Ruby. Is it just a global method `def Integer(x)` ?
[19:27:58] mlt-: Is there a way to autoreload stuff if I modify ruby code in an underlying gem I use in my Rails app? I mean do I have to explicitly ask Guard to watch those files or is there an automagic way to restart server if any of the local gems changed?
[20:18:24] FLeiXiuS: What's the best approach for handling static files like user avatars and file attachments in prod? I want these to be behind my rails authentication. Tips for prod / dev?
[21:15:36] FLeiXiuS: mlt-, I think I have 2 issues here. I want pictures to be secure with cancan and attachments to be handled by X-Send-File
[21:19:08] FLeiXiuS: Now I have to create a controller method for displaying images and verifying perms.
[21:20:24] mlt-: are attachments way different than pictures? Can you handle them both the same way but keep a flag for disposition
[21:20:57] FLeiXiuS: Attachments can be photos in some cases. But I want to display user avatars for instance.
[21:21:00] mlt-: Since you do it for both pictures and attachments, I don't see much difference and need in another controller
[21:22:30] FLeiXiuS: Pictures are attachments. Pictures can be download and displayed in some instances.
[22:18:57] Radar: FLeiXiuS: My version of an answer to your question would be this: host them on S3, but make sure that they're only accessible via presigned URLs. Generate the URLs on your server.