#RubyOnRails - 25 July 2018
« Back 1 day Forward 1 day »
[04:48:39] osp2: hi all I'm going through the rails tutorial and decided to set up my project with rspec because that's what we use at work
[04:49:01] osp2: but I'm having a tough time following the tests in the examples because they don't use rspec (I think it's minitest instead?)
[04:49:19] osp2: does anyone have something they can link to so I can learn how to write the equivalent tests in rspec?
[04:49:45] osp2: e.g.: https://www.railstutorial.org/book/updating_and_deleting_users#code-unsuccessful_edit_test
[04:50:34] osp2: so I've been a "back end engineer" at work for almost a year now so I'm familiar with the M portion of rails mvc and I'm familiar with rspec since that's what we use
[04:51:20] sevenseacat: ok so you're good with rspec. which parts of the tests can't you translate to rspec?
[04:51:25] osp2: the portions of the tutorial where we tested models was easy for me to convert to rspec, but it's the controller/view/integration tests I'm having a tough time with
[04:52:36] osp2: undefined local variable or method `users_edits_path' for #<RSpec::ExampleGroups::UsersEdits::GETUsersEdits:0x000000067732c8>
[04:52:52] hkais: could someone confirm me, that RoR is the highly recommended doc generation tool rdoc?
[04:54:42] hkais: sevenseacat: sorry not native speaking. I am asking what is the recommended tool for generating api docs in rails?
[04:54:58] osp2: ah looks like I should've read the test in the example more deeply; you're right sevenseacat - I shouldn't have assumed the generated test should work out of the box
[08:02:16] cheeti: hi iam new to rails 5, after active job complete i want to refresh my home page i am using after_perform. how to refresh home page content
[08:29:36] tbuehlmann: cheeti: your application server and background job worker are different processes, so it's not that easy. one way would be to let the browser poll for updates and reload on a certain update. this could also happen via actioncable (websockets) or server sent events
[08:29:44] ariejan: cheeti: you'll need to notify the client browser to refresh. Look into action cable to send a message and handle that message in JS client side.
[10:42:13] garyserjj: is it good practise to have one's own ID field rather than rely only on rails's ID?
[10:48:24] garyserjj: i'm building a website with multiple users that can log in. One user has most privileges that's the main guy the one that creates other users, if there's only one user on the system then it'd be them. Other users have a tier less e.g. maybe administrative which could be the same or almost as much rights. And other users are just regular users. I could have one user model with a field stating whether administrative or not, and one
[10:49:13] garyserjj: So if I don't want to ever have to search for the mainguy, should I have my own ID field, that I can control? Or should I make a new model for the mainguy?
[10:51:52] ariejan: garyserjj: you have two options here: put everyone in the database and assign roles (a boolean 'admin' field might be enough) and use an Active Record scope to filter out admins.
[10:52:18] ariejan: garyserjj: the other option is to only store normal users in the database and allow admin access (for instance to namespaced /admin controllers) through HTTP basic auth.
[10:53:46] garyserjj: and if i had a string or int, it's still suggesting one user database that includes the main guy and i'd be using User.find(privilege:"mainperson")
[10:53:48] tbuehlmann: regarding the id issue: if you don't want people to see increasing id numbers so they can't assume the size of your data, just switch from using bigints to uuids
[10:54:30] garyserjj: if I am doing User.find for the mainperson, then i'm searching for the mainperson which i don't really want to have to do
[10:56:10] ariejan: garyserjj: User.admin.find(..) will only find admins. User.regular.find(...) will only find regular users.
[11:00:32] garyserjj: like it might just search out the admins once / when there's a change in admins, and then not have to search all users, merely search all admins. Or it might just be a shorthand for searching all users. I'd guess the former.
[11:01:58] garyserjj: what i don't like about that syntax though is it's the same syntax as one would use if there was an admin model that belonged to user. So the syntax makes the structure less clear
[12:57:02] mikhael_k33hl: How do I log in rails production mode? tried Rails.logger.info, but it doesn't seem to log in log/production.log
[12:58:06] ariejan: mikhael_k33hl: Check https://guides.rubyonrails.org/debugging_rails_applications.html#the-logger
[12:58:47] ariejan: mikhael_k33hl: Your configuration may have changed, that page tells you what to look for. (log level, where to log, etc.)
[12:59:53] mikhael_k33hl: ariejan: I can see config.log_level = :debug, but nothing that point to log to production.log even though I can see some logs there
[13:04:30] mikhael_k33hl: https://gist.github.com/marzdgzmn/c5146d9b9e83fb321c19233168d2e64b So there's no default logger in ruby rails?
[14:25:49] cjohnson: On rails 4.2, I'm using a postgres jsonb column, and rails knows it's a json column
[14:26:11] cjohnson: When I store the following json document, and then read it back out, I'm getting the json string, not the parsed value: "something"
[14:26:52] cjohnson: I recognize that top-level scalars is not universally supported so I'm wondering if I should expect to have to parse all values in rails, or if rails 4.2 just doesn't recognize top-level scalars yet and I need to add exception cases for that
[14:28:29] cjohnson: For clarification the ruby representation of my value would be "\"something\"" but I expect it to be parsed and become "something"
[15:09:11] havenwood: cjohnson: I've always stored Hashes or Arrays in jsonb, and they come out like they go in.
[15:09:53] havenwood: cjohnson: I think it just expects deserialized input. Seems it's serializing your already serialized code.
[15:10:31] havenwood: cjohnson: Seems odd to deserialize it just to serialize it again though. I've never stored something that's already json in jsonb. It'll need to reserialize it either way, since it's going to a binary format.
[15:13:01] cjohnson: havenwood: Sorry let me clarify, I seeded a json document directly into the database using SQL, and the full text of the jsonb document is "something"
[15:13:19] cjohnson: Then when I go to read that jsonb column, which rails knows to be jsonb, it reads the json string out, which is "something"
[15:15:32] cjohnson: I'm on 4.2. I even tested a top-level hash just to be sure it wasn't a case where older rails didn't support top-level scalars
[15:54:51] bonhoeffer: i cant update records on my production site. no problem in dev and not exceptions. any ideas?
[17:03:26] cjohnson: I'm writing a concern to fix this in rails 4. In my def self.included, what is the right syntax for calling define_method such that I can define an attr reader/writer on the included class?
[18:50:50] crankhar1er: I'm looking for a gem that can move the I18n key/value data out of files in the app and into some crud-like interface that can allow non-technical folks to manage the translations. Is anyone famililar with something along those lines?
[20:47:04] mlt-: Hello! I'm doing some nasty stuff in Rails, but being a noob I'm curious if it does what I expect it to do. I mean it does work alright. I'm not sure whether it is efficient approach. I'd appreciate a feedback https://gist.github.com/mlt/5988c3c3fd61858d13bd7c25891b9ecf#file-sql_to_csv_streamer-rb
[21:34:01] mlt-: Inside: Thank you for taking a look! I do use lots of PostgreSQL specifics and that is not an issue for me. I'm more concerned about memory overhead whether this approach is better than fetching everything, formatting into CSV and sending back in one shot.
[21:37:06] mlt-: also I was not sure whether it is okay to toss around a block like that. I just tried and it worked.
[22:10:05] Radar: mlt-: Seems to me like you've built the ETL tool all into the one file. May have some maintainability issues in the future.
[22:10:24] Radar: mlt-: Is the intention behind this tool to be a general tool where you can throw in _any_ sql and it'll dump it, or is it for a particular model?
[22:17:39] Radar: Something like this: https://gist.github.com/radar/7e9573acb5bad4def585774f2ceec345
[22:18:00] Radar: imo it's clearer what this is doing. It's extracting posts from a database and transforming them into CSV. Yours seems pretty generic and I worry about that.
[22:28:36] Radar: s2013: Life is good. I'm writing a talk for next week about hiring juniors. Similar line to my RubyConf talk, but for a more senior-heavy audience.
[22:28:56] Radar: [15:30:32] s2013: man i keep getting error r14 (memory quote exceeded) even though i have 2 dynos. .and its a basic basic app.. still cant figure out whats wrong
[22:29:24] havenwood: s2013: The amount of memory doesn't increase when you add dynos. It's memory-per-dyno.
[22:31:02] havenwood: Radar: I'm coming to Australia for YOW! in Sydney, Brisbane and Melbourne! Couldn't wait for next years' RubyConf AU.
[22:31:17] Radar: s2013: talk transcript is here: https://ryanbigg.com/2018/03/hiring-juniors if you prefer reading it.
[22:33:44] havenwood: s2013: I can't make Rails Camp in AU, but I'm going to the one in Yosemite in August.
[22:34:04] Radar: havenwood: re juniors: Me too :) It's my bread & butter at the moment so I'm a little invested in it. Hoping that the passion I have for it will rub off on others.
[22:37:57] s2013: man its sad this channel is < 200 people now.. used to be hundreds and hundreds :(
[22:43:51] havenwood: seem busy to me i guess cause i never go in there, so it get spammed when i do
[22:44:29] s2013: speaking of.. so i didnt write much code for a while but decided to get back into it again cause i missed it
[22:45:14] s2013: so im thinking whats the best way of approaching this.. basically a table that would only have one row.. its kind of like settings,but not really.. there is a settings gem but im not 100% sure that is the best.. this table would also hold like api keys
[23:18:43] cjohnson: Can I just make an initializer whose contents are module ActiveRecord module Type class Json def deserialize