#RubyOnRails - 22 March 2017
« Back 1 day Forward 1 day »
[00:07:41] linetrace: have to admit I’m newish to Rails, it there an advised method (Rails 5) to fetch just values from an ActiveRecord query, not instantiate models from the results in such cases (query just selects year & month of published page for building archive links)
[00:59:47] patarr1: If I require a file in my job.rb file, will the constants in that file be defined in all of the various classes/steps the job uses?
[01:04:46] patarr1: I made a config/initializers/exceptions.rb and have one line - require 'somelib/exceptions'
[01:05:05] patarr1: In lib/somelib/exceptions.rb I have a module Foo, and within it a couple StandardErrors defined.
[01:05:36] patarr1: When I load Rails, it complains with "undefined method `configure' for Foo::Module"
[01:21:18] matthewd: patarr_: If you manually define the Foo module in exceptions.rb, then it won't get autoloaded from foo.rb
[01:28:25] chrickso: anyone here familiar with both flask and ruby on rails? i know my way around flask pretty well but having to plug in all the extensions i need, some that aren't being maintained, is really putting me off using it for my next project. really finding myself drawn to rails being so 'everything i need in the box and up-to-date'. is rails really that much of a time-saver over something like flask? not interested in django
[01:31:04] Radar: I don't know much about Flask (tinkered, but haven't used it seriously). I have used Rails for 10+ years and I keep coming back to it as my favourite tool for building web apps.
[01:34:12] chrickso: Radar: very little. basically processes the request and gives you access to it and the cookie. litterally everything else you do yourself or attach some extension made by who know's who and not updated in several years
[01:39:00] chrickso: same deal, all that stuff is available but various degrees of some random guy hacked it together and you follow the instructions to connect it and get that functionality
[01:40:47] Radar: chrickso: Migrations, sending email and background jobs (at least, a common API for things that run background jobs) are built in. Testing framework integrations exist as well-maintained gems.
[01:42:14] chrickso: some things i read about rails is when things go wrong it can be hard to narrow in on where exactly its happening when all the 'magic' happening everywhere and they prefer something as bare as flask even if it means more work up front to save on the troubleshooting time later
[01:42:52] chrickso: i suppose after 10 years you don't deal with alot of that anymore but can you really recommend it with that in mind to a ~beginner?
[01:45:23] Radar: I think there's a lot of good architectural advice out there for Rails apps these days which help you avoid the common pitfalls.
[01:45:58] helpa: Rails 4 in Action - http://manning.com/bigg2 - An excellent book combining Rails and TDD/BDD development. Written by Rebecca Skinner, Steve Klabnik, Ryan Bigg, Yehuda Katz
[01:51:57] chrickso: also a concern of mine is how every tutorial seems to be almost too ~beginner and will be like 'heres how you make a basic user authentication/system' but theres very little on like enterprise level, super robust/secure user account/session setup
[01:57:35] baweaver: Most of it is out there and tested, and can be pointed to, but after a certain point tutorials become exceedingly rare
[01:58:56] matthewd: There's no "how to implement proper robust authentication" tutorial, other than "here's how to install [devise / similar]", because that's not a thing you should be doing
[02:00:23] chrickso: how about sessions, is rails default sessions setup backend sessions or just cookie-based?
[02:01:56] matthewd: If you want to store them in redis or the DB or whatever, then you'll need the appropriate gem
[02:02:55] matthewd: "Everything in the box" isn't "everything for every option you might choose to configure", but a reasonably comprehensive set of defaults
[02:03:29] chrickso: i was under the impression there was some attacks could be done with cookies based sessions and prevented with server-side sessions
[02:04:32] Radar: chrickso: Rails 4 in Action tries very hard not to be a miniature application. It's a very full-featured application which does cover authentication + authorization in a serious manner
[02:05:29] Radar: The publisher and I have parted ways... the TL;DR is over my or their dead bodies.
[02:06:09] Radar: I'd happily update the book for Rails 5 if the publisher gave me the rights to the book. Since they own it and they're... difficult... to work with, I do not wish to continue.
[02:06:40] Radar: One example: they took my neatly formatted XML content and turned it into one line of not-very-neatly-formatted XML.
[02:06:52] matthewd: The session contents are signed so the client can't manipulate them.. it's potentially open to a replay, but that's generally pretty limited in practice
[02:07:15] Radar: chrickso: !mtwr is my other book. Kinda like a sequel to R4IA but not in the normal sense.
[02:07:15] helpa: chrickso: Multitenancy With Rails - https://leanpub.com/multi-tenancy-rails-2 - An excellent book that teaches you about building a Multitenanted Rails application. Written by Ryan Bigg.
[02:07:41] Radar: You can think of MTWR as the answer to "I've done a beginner's tutorial for Rails, but I need a more serious project. What's out there?"
[02:08:12] Radar: chrickso: Happy to if someone wants to pay me full-time or part-time to do such a thing ;)
[02:09:01] Radar: heh. That's what I've done in the past. It's not a liveable wage (yet) so I do it in my spare time.
[02:10:26] chrickso: or this guys https://www.nateberkopec.com/blog/2017/03/10/how-i-made-self-publishing-about-ruby-on-rails.html
[02:25:37] mwlang: you’ve got the following as well as prior credentials to pull it off, but oh, the user pressure that ensues. :-)
[02:29:10] greghoggard: I have an ecommerce app that uses Devise on Rails 4 and ruby 2.3. How do I go about editing the destroy_user_session_path? I need it to perform a check upon signing out if the cart is empty to destroy it
[04:01:39] baweaver: mwlang: https://www.linkedin.com/in/keystonelemur/ - 2012 was the first "real" job, before that was a ton of freelancing work around town.
[04:04:41] baweaver: Still, nothing remotely compares to the jump in skill you get doing it full time.
[04:06:30] mwlang: if you’d asked me 5 years ago if I knew Ruby, I’d say, “yeah, I’m great at it.” You ask me today how good I was 5 years ago, I’d be like, yeah, I knew *nothing* back then.
[04:06:53] mwlang: Ruby’s one of those languages where the more I learn the more I realize I don’t know.
[04:08:34] mwlang: That’s true…but there’s something about Ruby that seems infinite. C, Pascal, and others I’ve worked with, the road to mastery was pretty quick…it gets to the point where anything new is just a better library.
[04:13:59] baweaver: He got interviewed by none other than Guido himself. Said it was the most terrifying and humbling experience of his life. He still got the job, but said he'll never say that one again.
[07:26:04] DaniG2k: i'm trying to write a tiny piece of coffeescript that enables or disables a form field based on a checkbox
[07:27:47] DaniG2k: basically no matter whether the checkbox is checked or not I cannot get the class 'disabled' to be added
[07:51:51] c0ldfront: and use ubuntu for windows to run redis and such if i need certain items that run in linux
[09:14:43] adac: Guys, sidekiq has this default queue latency check in /sidekiq/stats However this checks only the default queue I guess, right?
[09:24:11] rubyonrails123: I have a problem with devise and I18N. I will appreciate any help. I also wonder if anyone has faced the same problem.
[09:24:13] rubyonrails123: http://stackoverflow.com/questions/42907894/wrong-locale-when-using-before-action-authenticate-user
[09:40:04] dionysus69: anyone familiar with plugins that let user insert formulas in the text fields? similar to what MS word has with insert functions or equations
[10:47:47] GeorgesLeYeti: I want to return the content of a node. html = Nokogiri::HTML("<test>Does. <br/><br/> </test>")
[10:51:38] Guest77850: As I know, we can config how to store session in a Rails app. I want to know if it's possible we store session in two modes ? which means one part in browser and other part in cache like memcached ?
[10:53:52] DeusNeusEx: Hi i upgrated my rails 4 application to rails 5 and i dont know was is the problem: this is my model: http://pastebin.com/DsvrcL7f and i've this in the log /home/tmayet/Documents/Sites/Lab/Rails/AviGNU/app/models/conversation.rb:10: warning: invalid character syntax; use ?\s
[10:54:47] Guest77850: i have two profix for my whole sessions : one part start with user- and others part start with server- so how to config that ?
[10:55:23] vedu: Guest77850: I am not following you. seems like you need only the user session. not the rails cache
[10:57:10] Guest77850: to be more clear it is possible to have a part of my session in the server cache and another in the client browser (cookie)
[10:58:19] Guest77850: vedu: to be more clear it is possible to have a part of my session in the server cache and another in the client browser (cookie)
[10:59:14] vedu: The session is always stored in the browser cookie. But it is encrypted so you don't have to worry
[11:24:22] rikkipitt: Hey folks, i'm having toruble with actioncable. I can console.log out connect/disconnect, but the receive js method isn't triggered when I broadcast a message in an after_create callback... any ideas? the user is authenticated on the site and in actioncable.
[12:39:25] wems: I have a question, if you had worked for a client on a RoR based web application for record management. The client asks for the source code? What would you do guys? Would you be willing to sell the source code? Any idea what as to the equation to calculate the price? Thank you very much.
[12:57:23] matthewd: rikkipitt: Can you see the messages arriving in the browser websocket inspector thing?
[12:59:54] rikkipitt: do you think so? I'm getting these - https://gist.github.com/rikkipitt/f76e7b4e234384de6db2dacc7865391c
[13:00:22] rikkipitt: i'm using suspenders and am running the server using `heroku local` which utilises puma
[13:01:48] matthewd: I don't know whether heroku local runs multiple puma worker processes -- that could be a factor
[13:03:48] helpa: http://gist.github.com - Put your codes online with pretty syntax highlighting and the ability to embed it into other pages.
[13:37:00] mauro1254: Hi folks, I'm trying to use yarn + webpack in rails 5.1. Where can I find instructions on how to include libraries?
[14:01:58] Mohan: i am trying to build a simple polymorphic association with post & comment. Able to display comment field in post form but getting "Comment commentable must exist"
[14:02:45] Guest55617: i am trying to build a simple polymorphic association with post & comment. Able to display comment field in post form but getting "Comment commentable must exist"
[14:03:17] Guest55617: post model contain has_one :comment, as: :commentable, dependent: :destroy accepts_nested_attributes_for :comment, :allow_destroy => true
[14:43:01] SilentNinja1: Hi, I'm having issues to memcache localhost using Dalli Gem, raw telnet works on localhost 11211 or 127.0.0.1 11211
[14:49:18] pwnd_nsfw`: SilentNinja1, it'd help to provide code, a means of reproducing the problem, etc.
[15:06:29] matthewd: And I'll go out on a limb and guess you're not running AWS core infrastructure on localhost
[16:54:19] tentacle: I have a SaaS app and we am looking for a method to generate a unique 5 digit pin when a member signs up. I've thought about generating a number, verifying if it exists, and repeat, much like slug generation, but as member base grows, that will become increasingly heavy. I've looked at generating the pins as records and just finding a random unassociated one, but that means for every company that signs up, I have to generate
[16:54:19] tentacle: an excessive amount of records upon creation. Just wanting to know if anyone has done this and what method they've used.
[16:55:17] Papierkorb: tentacle: 5 digit pins wouldn't last long anyway; Isn't that just a one time thing?
[16:57:48] Papierkorb: tentacle: if it's much less than that, say 100 top, I wouldn't bother and just do a random-loop like you thought about. the possibility of hitting an already used pin is rather small
[16:59:51] Papierkorb: tentacle: does a 5 digit pin even suffice? That's a 10% chance I'd find a matching key, or 10 tries max to brute-force my way in
[17:00:43] tentacle: Papierkorb: while it sounds like it's for security, it's more about tracking who is checking in
[17:03:41] tentacle: Papierkorb: think of it more as a checkin service, but we need unique pins so we know which user to map the pin to
[17:06:36] Papierkorb: tentacle: If you fear a random-loop taking too long, you could create those 100k possible rows, set them to NotUsed, and when you need a new pin, just select one randomly from the NotUsed ones, mark it as Used, and go on. Can't tell you about the run-time of this though
[17:07:09] tentacle: Papierkorb: that was the solution I opted for, but was just wondering if anyone had any other suggestions instead of pre-creating and associating. Thanks :)
[17:10:31] IanMalcolm: guys, I'm trying to write a test with RSpec to make sure a user can't be created twice, but I'm not sure how to go about it. I need to create the record on the database and then POST to the API endpoint the same data
[17:10:44] matthewd: tentacle: If the random loop seems too slow, that would seem to imply you're over-filling the keyspace (read: need more digits)
[17:11:12] tentacle: matthewd: yeah it's an interesting situation because we can't have more than 5 digits :D
[17:11:31] matthewd: tentacle: Even if it's not "must be unguessable with a bunch of tries" level security, you don't want someone's typo to (statistically) be someone else's valid PIN
[17:12:10] tentacle: matthewd: agreed, it's a flawed setup, but unfortunately it's what the client wants :3
[17:15:14] matthewd: Even at 10% fill, it shouldn't take *that* many tries to come up with an unused value
[17:19:09] patarr: How do I ensure the bin/delayed_job daemon has the same load path as the Rails app?
[17:19:27] patarr: It seems like Rails loads all the names just fine, but delayed_job gets NameErrors.
[17:23:35] matthewd: patarr: I don't know anything about delayed job in particular, but you should be running it under bundler (bundle exec), and it should be loading config/environment when it starts
[17:39:06] psethi: Hi Folks, how can I install rails 5.1. I followed this article https://bendyworks.com/blog/installing-ruby-on-rails-edge-with-bundler but still after completing all the steps and getting success, it still displays Rails 5.0.2, when I do rail -v
[17:46:52] matthewd: psethi: That's installing edge from git; you can just install the release candidate
[17:53:02] dminuoso: What exactly are "references" in migrations? Are these just conventionally named integer columns?
[17:58:50] cnk: I think now they actually make FK relationships in the database, but haven't been keeping track of rails + db constraints changes
[18:01:27] dminuoso: cnk: I have stumbled over this a few times and now I ended up with a corrupt database because I kept assuming there were constraints..
[18:02:11] cpruitt: dminuoso: I believe that by default it is an integer column for relation_id with a foreign key constraint and an index.
[18:02:37] cnk: Rails has always done its contraining in ActiveRecord. Only recently has it supported FK constraints
[18:03:10] cnk: Not supporting db constraints made a lot of things like loading fixtures, etc easier
[18:04:22] cnk: Personally I use a mix. Fixtures are quite efficient if you need a lot of setup data for anything to run
[18:04:47] psethi: matthewd: Thanks, it worked. earlier I had tried "gem install rails -v 5.1", which didn't work
[18:04:58] cpruitt: dminuoso: Take that back. I just checked and I am specifying foreign_key: true in all of mine
[18:05:32] dminuoso: cpruitt: Im unsure how Im missing this foreign key constraint because I never opted out of it.
[18:06:37] matthewd: dminuoso: Did you create the column using t.references (not t.integer), in a 5.0 migration?
[18:06:50] cpruitt: dminuoso: My first comment was incorrect. the foreign_key option defaults to false http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_reference
[18:09:24] dminuoso: Let me recreate and play back migrations one by one to figure out what went wrong.
[18:56:23] Andr3as: hmm.. if i have a text input for a (single) username and would want to style the entry that it looks like a tag, but only want to allow one value.. is there a special name for that? anyone an idea what to google for? i am totally lost in translation
[21:15:05] Schoolmeister: Hey. Say I've got two tables: "Events" and "People", and a third table "Attendees" which represents a many-to-many relation of People and Events. How would I go about rendering a list of attendees in the show view of event?
[21:17:37] cnk: Set up your relationships in the model, then make a var @attendies = @event.attendees in your controller and loop over it in yoru view
[21:18:27] diggitydane: react frontend with rails api. I need to save an array of objects to postgres. how should the column be defined? params comes through as a string, and then JSON.parse when I return results with api calls?
[21:18:31] fox_mulder_cp: agent_white: thanlks. may be may rails app can be used in my new job tasks )
[21:19:11] diggitydane: I tried hstore :column, array: true, and serialize :column, Array in the model, but seems to be a big hassle. should i just leave it as a string?
[21:46:52] centrx: Is backbone.js the way to go for organizing front-end ajax panels on a dashboardy like UI?
[21:49:15] Axsuul: in rspec, in an example, I'm trying to make it so that when calling a method on this one record, it returns a specific array but I can't use double() because it's being called from within a controller (this is a request spec)
[21:49:54] centrx: baweaver: it show some info to call-center agents and allows them to edit things, click on a few buttons, etc.
[21:50:06] centrx: baweaver: other things like, if they click on a row in a grid, it opens up a different call to edit it
[21:50:47] centrx: what about Angular being replaced by the Angular 2 rewrite? I heard the rewrite was not so good
[22:01:33] helpa: rubyonrails525: Don't ask "does anyone use <thing>?". It's better to just state your problem and if anyone has used <thing> they will most likely answer.
[22:01:38] helpa: Rails 4 in Action - http://manning.com/bigg2 - An excellent book combining Rails and TDD/BDD development. Written by Rebecca Skinner, Steve Klabnik, Ryan Bigg, Yehuda Katz
[22:04:59] rubyonrails525: I'm trying to make a put to a nested route, but I'm getting this error ActionController::UrlGenerationError: No route matches
[22:08:51] helpa: rubyonrails525: What "didn't work"? Did your server not start? Did your computer explode? Did your webpage turn bright pink? Did your client not pay your bill on time? You may have to be more specific. A Gist (http://gist.github.com) of the code that doesn't work (and the error you are getting) will be helpful.
[22:23:35] Radar: rubyonrails525: Your route is nested several times and you need to specify a parameter for each level of nesting
[22:42:46] rubyonrails525: Someone can help me with this test, please? https://gist.github.com/evaldosantos/6e4854fedc854fce8e2a5844fecf0f00
[22:43:20] Radar: [09:23:33] <Radar> rubyonrails525: Your route is nested several times and you need to specify a parameter for each level of nesting
[22:43:49] Radar: dminuoso: is now a good time to tell you that in Phoenix partials are just functions? ;)
[22:50:06] Radar: dminuoso: asking the brainstrust about a faster json renderer... but they're all asleep.
[22:50:30] dminuoso: Radar: Honestly its an edge case anyway. I can live with 2-3s view render time.
[22:51:52] Radar: dminuoso: I've got an example of caching here: https://github.com/radar/twist/blob/asciidoc/app/controllers/accounts/elements_controller.rb#L8
[22:52:16] Radar: The elements are only ever updated when the chapter is updated. `fresh_when` will send a 304 Not Modified if the chapter's timestamp hasn't changed.
[22:52:34] Radar: This relies on client-side caching. You can also do server-side caching. Maybe we'll talk more about it tomorrow :)