« Back to channel list

#RubyOnRails - 20 November 2017

« Back 1 day Forward 1 day »
[00:04:13] someish: has joined #RubyOnRails
[00:04:56] Sylario: Radar: It seems that libruby.so.2.3 is the one missing
[00:05:35] workmad3: has joined #RubyOnRails
[00:12:14] Sylario: Ok so RVM is horrible for production, apt-get is worse, what do I use?
[00:13:13] Radar: ruby-install
[00:26:32] LateralO1: has joined #RubyOnRails
[00:28:01] mtkd: has joined #RubyOnRails
[00:30:47] sevenseacat: has joined #RubyOnRails
[00:40:04] Ropeney: has joined #RubyOnRails
[00:50:29] pbmarcano: has joined #RubyOnRails
[00:53:15] Sylario: How do I integrate ruby with the OS once I have installed with ruby-install ?
[00:55:58] one_zero: has joined #RubyOnRails
[00:57:03] mcr: https://github.com/postmodern/ruby-install <- this what you are speaking of?
[00:59:33] cagomez: has joined #RubyOnRails
[01:01:26] Sylario: it seems I can use chruby
[01:04:12] apeiros: has joined #RubyOnRails
[01:21:16] hfp_work: has joined #RubyOnRails
[01:28:56] pbmarcano: Hi, I am hoping someone can help me find the right words or phrase to google here
[01:31:01] pbmarcano: I am building an application where someone fills out a form, and gets asked for references. When they supply the email of a reference, I want to send the reference an email with a link to click, and then the link will bring the reference back into the application to fill out their reference form. I don’t want the reference to create an account to do so, just simply click ‘provide reference’ and then they get navigated to a simple web form tha
[01:31:02] pbmarcano: will pull the parameters and stuff to make sure ActiveRecord files the reference in the right place.
[01:32:14] pbmarcano: Obviously I don’t want this to be able to be spoofed, but I also don’t want people creating accounts to type in a text box… something like a token in a URL that can create a small session for the guest? Is there an gem for this? What is this kind of fake authentication called? What do I even google? Sorry.
[01:33:01] mcr: pbmarcano, yes, I've done this before.
[01:34:43] mcr: so, yes, you want to put a token in the URL that you generate. It should index into a table. The token should be some randomly generated number, Base64::urlsafe_encoded().
[01:35:48] cagomez: has joined #RubyOnRails
[01:36:12] mcr: You don't want "fake authentication", just no authentication, with the form brought up because of the URL. You may want to expire the token after use, and perhaps expire it after some period of time as well.
[01:39:46] pbmarcano: yes all of that would be ideal! So a table in the database would reference the application, and have strings for an email address, a secret that is encoded and put in the url, and a text value for their actual reference? Does that seem like the minimal amount of data needed? I feel like this feature is implemented enough that it would have a name but I can’t figure it out enough to even google it
[01:40:40] pbmarcano: and an expiration date… as you mentioned, mcr
[01:46:48] Technodrome: has joined #RubyOnRails
[02:05:53] workmad3: has joined #RubyOnRails
[02:07:30] pbmarcano: has joined #RubyOnRails
[02:07:56] pbmarcano: Sorry mcr if you answered. Terrible time for my internet to cut out
[02:31:59] mcr: what's the text value for their reference?
[02:33:09] mcr: Oh, you might as well just Base64::urlsafe_encode64(SecureRandom.random_bytes(12))
[02:33:34] mcr: and use that as your url token and value in the text column. No reason to store both binary and base64 version.
[02:35:04] Jameser: has joined #RubyOnRails
[02:48:59] orbyt_: has joined #RubyOnRails
[03:18:36] xlegoman: has joined #RubyOnRails
[03:36:46] MrCrackPotBuilde: has joined #RubyOnRails
[03:37:19] Technodrome: has joined #RubyOnRails
[03:53:30] srinidhi: has joined #RubyOnRails
[03:59:52] Saukk: has joined #RubyOnRails
[04:06:14] workmad3: has joined #RubyOnRails
[04:19:23] Technodrome: has joined #RubyOnRails
[04:24:09] cagomez: has joined #RubyOnRails
[04:32:05] easzero: has joined #RubyOnRails
[04:42:32] quazimodo: has joined #RubyOnRails
[04:51:26] freedrull: has joined #RubyOnRails
[05:03:54] Puffball: has joined #RubyOnRails
[05:04:29] duderonomy: has joined #RubyOnRails
[05:04:33] mikecmpbll: has joined #RubyOnRails
[05:07:44] quazimodo: has joined #RubyOnRails
[05:32:32] ur5us: has joined #RubyOnRails
[05:38:17] iamarun: has joined #RubyOnRails
[05:40:39] quazimodo: has joined #RubyOnRails
[05:42:35] MagicGuitarist: has joined #RubyOnRails
[05:43:33] ur5us: has joined #RubyOnRails
[05:51:31] Jameser: has joined #RubyOnRails
[06:06:30] workmad3: has joined #RubyOnRails
[06:23:04] easzero: has joined #RubyOnRails
[06:36:11] apeiros_: has joined #RubyOnRails
[06:50:17] apeiros_: has joined #RubyOnRails
[06:51:18] urkle: has joined #RubyOnRails
[06:59:40] MrCrackPotBuilde: has joined #RubyOnRails
[07:01:50] kapil___: has joined #RubyOnRails
[07:19:49] kapil___: I created object with Model.create method . How should i know that it saved?
[07:22:21] sevenseacat: check the return value
[07:23:06] kapil___: it ruturns object. not true or false.
[07:23:19] sevenseacat: right. is the object saved?
[07:23:37] sevenseacat: then it saved.
[07:23:57] kapil___: but i have if condition i should check it saved?
[07:24:12] Dimik: has joined #RubyOnRails
[07:25:35] baweaver: If you want to make sure it saved use create!
[07:25:45] baweaver: or use new and then save it later to make sure
[07:25:58] kapil___: but i want true or false in if condition.
[07:26:30] sevenseacat: right, so what did you do to check if it saved? do that in the if condition
[07:26:58] baweaver: record = Model.new(params); if record.save; do good stuff; else show record.errors end
[07:27:46] kapil___: its the way
[07:28:41] kapil___: and for update?
[07:29:01] baweaver: I'll leave that as an exercise in reading the documentation
[07:29:21] kapil___: ok update also return an object.
[07:35:15] conta: has joined #RubyOnRails
[07:50:35] kapil___: sorry update returns true or false. thank you..
[08:02:32] Jameser: has joined #RubyOnRails
[08:06:43] workmad3: has joined #RubyOnRails
[08:16:03] Andr3as: good morning everyone... i was trying to extend the String class like this https://stackoverflow.com/a/5654580/6844761
[08:17:10] Andr3as: made the initializer and my string.rb file like this: https://gist.github.com/awunder/27e7028385d78413077a06d90c2cadce
[08:17:50] Andr3as: however, i am getting "NoMethodError: undefined method `to_impact' for "test":String" when i test this on the console
[08:18:20] Andr3as: anyone an idea what i am doing wrong?
[08:18:41] Andr3as: i restarted the console.. just for the records
[08:19:07] sevenseacat: where is that core_ext.rb ?
[08:19:32] sevenseacat: and where is that string.rb /
[08:20:30] Andr3as: string.rb is in /lib/core_ext/ --- core_ext.rb is in /config/initializers
[08:20:51] sevenseacat: have you restarted spring?
[08:21:09] Andr3as: i was on the console and made a "reload!"
[08:21:23] sevenseacat: thats not restarting the console or spring
[08:22:39] Andr3as: i see.. had to kill spring.. a simple console reload or restart did not work
[08:22:50] Andr3as: thank you sevenseacat!
[08:26:48] dminuoso: Mmm. Dont we already have something like that in AS?
[08:28:08] sevenseacat: sure, but thats not what theyre trying to do
[08:34:50] one_zero: has joined #RubyOnRails
[08:45:58] roshanavand: has joined #RubyOnRails
[08:53:57] dionysus69: has joined #RubyOnRails
[09:01:07] noob_on_rails: has joined #RubyOnRails
[09:01:30] noob_on_rails: hey all , what is a good practice when breaking a large Class
[09:02:02] noob_on_rails: refactor wise.. It's just a class instantiated by a controller at some point to get some data back
[09:02:16] sevenseacat: depends on why youre breaking it up
[09:04:50] mikecmpbll: has joined #RubyOnRails
[09:12:40] mtkd: has joined #RubyOnRails
[09:12:45] ur5us: has joined #RubyOnRails
[09:13:04] Doldge: has joined #RubyOnRails
[09:19:29] DoubleMalt: has joined #RubyOnRails
[09:20:02] noob_on_rails: has joined #RubyOnRails
[09:20:50] andatche: has left #RubyOnRails: ()
[09:25:48] dviola: has joined #RubyOnRails
[09:28:05] wethu: has joined #RubyOnRails
[09:31:23] ur5us: has joined #RubyOnRails
[09:35:27] noob_on_rails: sevenseacat: umm , better code reasons ?
[09:35:36] sevenseacat: yeah, what reasons?
[09:35:46] sevenseacat: 'better code' isnt a reason'
[09:36:05] noob_on_rails: well it's the largest class of the whole app
[09:36:15] noob_on_rails: it could use some refactoring i guess
[09:36:20] noob_on_rails: i've fought with some one liners
[09:36:39] noob_on_rails: but it could go on to become something more beautiful
[09:37:07] noob_on_rails: i thought the refactoring reasons are pretty clear :p
[09:37:10] sevenseacat: if you dont know what you want to achieve by refactoring it, I can't really offer any advice
[09:39:20] marr: has joined #RubyOnRails
[09:46:18] _aeris_: has joined #RubyOnRails
[09:46:31] _aeris_: hello here !
[09:47:10] _aeris_: i search a way to implement custom view lookup for actionmailer, has somebody got some clue about it ?
[09:47:31] _aeris_: i try to implement some fallback behaviour regarding model attribute value
[09:48:00] _aeris_: for example, given a @model.slug, will look for slug/mailview.txt then mailview.txt
[09:52:21] one_zero: has joined #RubyOnRails
[09:55:37] marienz: has joined #RubyOnRails
[10:07:02] workmad3: has joined #RubyOnRails
[10:10:51] apeiros: has joined #RubyOnRails
[10:11:46] lxsameer: has joined #RubyOnRails
[10:16:50] sekmo: has joined #RubyOnRails
[10:22:15] dminuoso: Oh man I want to shallow render views for isolated view tests..
[10:22:23] dminuoso: Is there something like enzyme that can do this with rails views?
[10:25:42] dminuoso: This is particularly nasty for cells. Im not exactly sure whether this is possible outside the realm of react.
[10:29:54] noob_on_rails: has joined #RubyOnRails
[10:31:30] FastJack: has joined #RubyOnRails
[10:31:54] DrYockel: has joined #RubyOnRails
[10:42:29] gregf_: has joined #RubyOnRails
[10:53:00] MrCrackPotBuilde: has joined #RubyOnRails
[10:55:23] MrCrackPotBuilde: ive managed to learn how to send an email via rails and everything works perfect in dev and production. I have a question though that i cant find info on. Its easy to style the website form but how about styling the sent email. Is there a way to create a template then use erb to input the fields then send that. IE contact form has name email body. at the minute it emails like this [ "message + email + name" ] (exactly like that)
[10:56:05] MrCrackPotBuilde: i want a standard form with pics logo etc then have the name imported into the template
[10:56:22] MrCrackPotBuilde: i bit like agoda's way of confirming bookings with hotels
[10:58:04] dminuoso: MrCrackPotBuilde: Yes.
[10:58:24] dminuoso: MrCrackPotBuilde: View a view (be it a partial or not) as just an abstract function that, given some parameters, produces some HTML.
[11:01:14] dminuoso: MrCrackPotBuilde: Its no different from websites, except things like CSS are a bit strange to use.
[11:15:54] arBmind: has joined #RubyOnRails
[11:21:17] Macaveli: has joined #RubyOnRails
[11:31:22] jonno112: has joined #RubyOnRails
[11:32:08] jonno112: Hey guys, I'm trying to get rspec setup with an already existing Rails project. For some reason, tests are always running in the 'development' environment.
[11:32:46] jonno112: I've ssh'd into the container and confirmed the environment is 'test'
[11:33:19] apparition: has joined #RubyOnRails
[11:33:28] dminuoso: By `container`, do you mean docker container?
[11:33:34] jonno112: But checking from within a test, the environment is 'development'. I'm wondering whether it's due to the Puma instance that's running the server locally.
[11:33:49] dminuoso: jonno112: Please gist your Dockerfile and your spec_helper.rb, rails_helper.rb and the test you are running.
[11:33:57] jonno112: Sure - 2 minutes
[11:40:21] jonno112: dminuoso: here are the files, I've added puma.rb and a single test asserting the correct database :) https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20
[11:40:33] dminuoso: The more files the merrier.
[11:40:50] dminuoso: jonno112: How are tests invoked?
[11:41:09] jonno112: getting a bash session in the running container, and running `rspec`
[11:42:25] dminuoso: jonno112: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-spec_helper-rb-L19
[11:42:50] jonno112: dminuoso: a stackoverflow suggestion! haha
[11:43:19] dminuoso: jonno112: Before you run rspec, can you check your environment variable RAILS_ENV in the shell?
[11:43:40] jonno112: it's blank!
[11:44:06] dminuoso: jonno112: Do you have an editor in your docker container?
[11:44:17] dminuoso: (Asking because I dont :D)
[11:44:19] jonno112: I can get one quite easily :)
[11:44:49] jonno112: just installed vim
[11:45:03] dminuoso: jonno112: I would modify the spec_helper.rb to put out ENV['RAILS_ENV'] to see whats going on.
[11:45:33] dminuoso: jonno112: Also, are there any funky rspec plugins or rack middlewares loaded, that do "magical things" ?
[11:45:49] jonno112: quite possibly. this is legacy code I'm integrating with!
[11:45:59] jonno112: how might I identify it?
[11:46:55] dminuoso: jonno112: Staring at your Gemfile and `rails middlewares` output, and use your gut feeling.
[11:47:03] dminuoso: That's what I'd do :P
[11:47:16] jonno112: ok I've puts'd the environment inside rails_helper -> Rspec.configure block
[11:47:20] jonno112: it shows as test
[11:47:35] dminuoso: jonno112: rspec by default places it in rails_helper directly at the top after requiring 'spec_helper'
[11:48:21] dminuoso: But I suppose any place where it makes things "work" would be fine.
[11:48:28] dminuoso: Still wondering why this works.
[11:48:35] jonno112: What do you mean?
[11:49:38] dminuoso: jonno112: Try this. Open up the exact spec that fails, and insert another assertion: expect(Rails.env.test?).to be(true)
[11:50:52] jonno112: dminuoso that passes!
[11:51:03] jonno112: but the other test still fails
[11:51:19] dminuoso: jonno112: Show me your database.yml (feel free to sanitize any passwords and addresses, but keep the entire file intact otherwise)
[11:52:27] jonno112: dminuoso: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-database-yml
[11:52:59] wethu: has joined #RubyOnRails
[11:53:15] jonno112: and before you ask...
[11:53:31] dminuoso: This is working well. You know what Im interested in next.
[11:53:42] jonno112: expect(ENV['DATABASE']).to match(/app_test/)
[11:53:48] jonno112: that passes ^
[11:56:14] jonno112: dminuoso: did I guess correctly? :P
[11:56:19] jonno112: thanks for the help so far btw
[11:56:20] dminuoso: jonno112: :)
[11:57:43] dminuoso: jonno112: I've got to ponder on this for a moment.
[11:57:59] jonno112: cheers dminuoso :)
[11:58:51] dminuoso: jonno112: Just to rule out some bizarre things happening. What is the DATABASE environment variable in the shell you run rspec from?
[11:59:21] dminuoso: (Want to make sure there isn't some component that has mutated ENV after the connection has been established, making us see weird things)
[11:59:39] jonno112: it's blank actually
[11:59:50] dminuoso: So. This has just become interesting.
[12:00:03] jonno112: Whereas the tested database value == 'postgres'
[12:00:11] jonno112: (from ActiveRecord::Base.connection_config)
[12:02:32] dminuoso: jonno112: On an unrelated side-node, your default: &default hash has some rather redundant keys `username` and `password`
[12:02:55] jonno112: dminuoso: agreed
[12:03:02] jonno112: Plus discrepancies in naming too
[12:03:16] jonno112: DATABASE_NAME on some == DATABASE on others
[12:03:40] jonno112: (inherited code - I'm going to go through and remove any weird discrepancies at some point)
[12:03:57] dminuoso: jonno112: Right. Ive stumbled over it because I was wondering whether this could have an impact somehow.
[12:04:36] dminuoso: Which rails version is this?
[12:05:22] jonno112: actually that might be it tbh
[12:05:32] jonno112: it's Rails 5 :)
[12:05:46] dminuoso: Just want to know the exact version because Im about to look at the source.
[12:06:50] jonno112: ok fixed it
[12:07:00] jonno112: that was embarrassingly simple
[12:07:04] dminuoso: What was it?
[12:07:12] workmad3: has joined #RubyOnRails
[12:07:36] jonno112: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-database-yml-L65 - changed this to DATABASE_NAME, like the others
[12:07:44] jonno112: *facepalms*
[12:08:00] jonno112: dude you're a lifesaver!
[12:08:39] jonno112: spoke too soon. I actually didn't fix it at all. Sorry haha
[12:08:47] jonno112: I've switched it nonetheless though
[12:08:54] dminuoso: jonno112: Yeah, I dont see how.
[12:09:12] jonno112: got over excited there
[12:09:20] dminuoso: jonno112: Please add your config/environment.rb and your config/environments/test.rb
[12:09:35] dminuoso: There's something quirky about the boot process that defaults to a database that was never configured.
[12:10:27] dminuoso: jonno112: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-rails_helper-rb-L2 as you can see, this is how rails is loaded by rspec. So the file (and the file I expect it to load) are of particular interest now.
[12:10:45] dminuoso: jonno112: Also go through your initializers, see if there's any that messes with the connection.
[12:11:17] jonno112: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-config-application-rb
[12:11:21] jonno112: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-config-environments-test-rb
[12:11:42] dminuoso: jonno112: Wrong file on the first. Im interested in config/environment.rb not config/application.rb
[12:12:22] jonno112: sorry that's the correct file - naming mistake!
[12:12:25] dminuoso: Oh wait that is it.
[12:12:36] dminuoso: jonno112: Include your config/application.rb :P
[12:12:46] arBmind: has joined #RubyOnRails
[12:12:47] dminuoso: The irony is hilarious.
[12:13:57] MrCrackPotBuilde: dminuoso do you have any documentation on it still struggling to find
[12:14:04] jonno112: Btw - yes - seeing the setting of the environment variable made me nervous too...
[12:14:05] jonno112: https://gist.github.com/jonlambert/04cb08659f6e0335150829e50f134f20#file-config-application-rb
[12:14:13] dminuoso: jonno112: Also... that initial spec that failed... what does ActiveRecord::Base.connection_config[:database] equal to?
[12:14:24] jonno112: dminuoso: `postgres`
[12:14:49] dminuoso: That sounds so wrong
[12:14:58] drowze: has joined #RubyOnRails
[12:16:11] dminuoso: jonno112: Is that value from before you touched your database.yml?
[12:16:15] jonno112: I know right
[12:16:30] jonno112: Before I changed to `DATABASE_NAME` you mean?
[12:16:49] jonno112: Yep. And the same now. `postgres` is the development database name
[12:18:13] dminuoso: jonno112: This makes no sense.. I'd try and provoke an error. Modify your database.yml so that development has valid YAML but settings that are unusable. Say an invalid URI.
[12:18:32] jonno112: hmm I would but -
[12:18:40] jonno112: the container will immediately exit wont it?
[12:19:02] dminuoso: jonno112: Is this a production container?
[12:19:06] jonno112: so I won't be able to exec bash and run rspec
[12:19:15] jonno112: nope it's a development environment
[12:19:22] dminuoso: jonno112: It shouldn't because the application is already running.
[12:19:31] jonno112: ah I see what you mean
[12:19:36] dminuoso: (And if in doubt you can change the final run to do some busy sleep)
[12:19:57] dminuoso: i.e. the CMD
[12:20:40] jonno112: ok doing the latter!
[12:21:01] dminuoso: jonno112: Or better yet...
[12:21:06] dminuoso: jonno112: Just delete the entire `development` portion.
[12:21:15] dminuoso: jonno112: The part that tries to read it might choke. ;-)
[12:21:23] jonno112: will that be reflected immediately or will I need to restart anything?
[12:21:30] dminuoso: But its beyond me where the `postgres` even comes from.
[12:21:42] dminuoso: jonno112: if you change your Dockerfile you have to rebuild and rerun it.
[12:21:52] dminuoso: jonno112: But it shouldnt be necessary. Just modify your database.yml you will be fine
[12:22:00] jonno112: Yep I mean if I change database.yml will it hot-reload?
[12:22:14] jonno112: Tbh I'm not wholly used to Rails' spring and puma
[12:22:20] dminuoso: jonno112: nope
[12:22:36] dminuoso: jonno112: spring.. i've thought about that..
[12:22:52] dminuoso: I dont see how but..
[12:22:53] jonno112: apparently it's not running!
[12:23:00] jonno112: I tried killing it
[12:23:02] dminuoso: Good, it better not.
[12:23:21] dminuoso: I have a picture on my desk that reads "If in doubt, kill spring"
[12:23:55] dminuoso: jonno112: Here's another thing that comes to mind.
[12:24:21] jonno112: it came as a surprise when I was getting started with this codebase
[12:24:31] dminuoso: I think I just found your mistake.
[12:24:35] jonno112: Oh really?!
[12:25:37] dminuoso: jonno112: Let me show you the way spec is canonically used.
[12:26:01] jonno112: That'd be great
[12:26:50] jonno112: btw - run the container with sleep 3000
[12:27:04] jonno112: running rspec still has the same output
[12:27:21] dminuoso: jonno112: just CMD /bin/sh
[12:27:25] dminuoso: Yeah I know.
[12:28:05] jonno112: I would do that but I'm running from within a docker-compose thing, it's just easier to grab a session using exec :P
[12:28:15] dminuoso: jonno112: https://gist.github.com/anonymous/20751919d099b2d7d59dc365d82daac0
[12:28:47] dminuoso: jonno112: Your rspec setup of which files include what is just messed up in a way that it does things in the wrong order.
[12:28:56] jonno112: Ahhhhhhh I see
[12:29:01] dminuoso: If you follow the scheme I laid out it should work.
[12:29:08] jonno112: Dude thanks so much.
[12:29:14] jonno112: Let me try it out and get back to you
[12:29:20] jonno112: that makes a lot more sense
[12:30:30] truenito: has joined #RubyOnRails
[12:31:10] dminuoso: jonno112: So rails basically defaults to picking the development database if no RAILS_ENV has been specified (which is why `rails s` ends up using the development adapter).
[12:31:35] jonno112: I was going to say - is it safe to default to env = test in rails_helper?
[12:31:48] dminuoso: And since you "require the rails environment.rb" (which essentially loads the rails application) before RAILS_ENV has been set.. you get that behavior. Later you then set ENV to `test`, leading to this bizarre behavior.
[12:31:56] dminuoso: jonno112: Yes.
[12:31:58] jonno112: aha makes sense!
[12:32:03] dminuoso: jonno112: You should in fact, or you have to specify it explicitly
[12:33:32] dminuoso: jonno112: And then in your specs you just require either 'rails_helper' or 'spec_helper' depending on whether you want the rails specific config of rspec or not.
[12:34:52] dminuoso: What Im not sure about, is how it default the DATABASE name to `postgres`.
[12:36:36] jonno112: Tests are failing still. The environment is now showing as `development`
[12:36:56] jonno112: I've ensured only rails_helper is being loaded in the test
[12:37:43] jonno112: dminuoso: I've modified it to look like this https://gist.github.com/jonlambert/ae40ff3836b4cd6cbdb301fb6e8ca2ee
[12:38:16] dminuoso: jonno112: Wrong order still.
[12:40:11] dminuoso: jonno112: RAILS_ENV needs to be set *before* config/environment is required.
[12:40:20] jonno112: have just updated
[12:40:28] jonno112: still showing 'postgres' aaaaaaaahhh
[12:40:36] jonno112: https://gist.github.com/jonlambert/ae40ff3836b4cd6cbdb301fb6e8ca2ee
[12:42:13] dminuoso: jonno112: rename the key `development` to something else.
[12:42:15] dminuoso: This should blow up.
[12:42:21] dminuoso: If not, then Im out of guesses.
[12:42:36] dminuoso: Im completely unsure how it arrives at `postgres` at all.
[12:42:36] jonno112: where should I rename? :)
[12:42:41] dminuoso: jonno112: in your database.yml
[12:42:44] dminuoso: or delete it
[12:42:52] dminuoso: in fact, rename the entire file.
[12:42:58] dminuoso: Make it explode.
[12:43:09] tcopeland: has joined #RubyOnRails
[12:43:14] dminuoso: jonno112: At this point Im wondering what kind of initializers you have.
[12:43:23] dminuoso: They are the last thing we have not looked at yet.
[12:43:31] dminuoso: Also your Gemfile.
[12:43:39] dminuoso: If there's funky requires, then well.
[12:46:34] jonno112: If I remove database.yml it blows up
[12:46:43] jonno112: `rescue in connect': FATAL: role "root" does not exist (ActiveRecord::NoDatabaseError)
[12:46:50] jonno112: but then I guess that's expected
[12:49:47] jonno112: dminuoso: Just looked through all initialisers and can't see anything setting the environment
[12:50:30] Kutakizukari: has joined #RubyOnRails
[12:51:33] jonno112: dminuoso: if I rename the development key to something else it still loads postgres
[12:53:37] dminuoso: jonno112: Can you give me a stack trace on that?
[12:53:43] dminuoso: Because that is the last error I would expect.
[12:53:58] jonno112: Renaming test gives the same error actually
[12:54:00] dminuoso: It should give something like `resolve_symbol_connection': 'development' database is not configured.
[12:54:19] dminuoso: At this time include your Gemfile please.
[12:54:28] dminuoso: Something is interfering with the initialization process.
[12:54:31] dminuoso: Some Railtie perhaps
[12:58:33] jonno112: dminuoso: https://gist.github.com/jonlambert/ddd81f59c8d283564861effde34d9a68 :)
[13:00:17] dminuoso: jonno112: Thats with the database.yml removed?
[13:00:26] dminuoso: You must have some initializer or railtie that is interfering.
[13:00:31] jonno112: that's with the test key renamed to test2
[13:00:42] jonno112: Gemfile inbound...
[13:00:44] dminuoso: jonno112: Rename every key to something else
[13:01:24] dminuoso: jonno112: The idea is to provoke Rails.application.initialize! to fail.
[13:01:57] dminuoso: The fact that it didnt fail, suggests it found a database configuration its happy with.
[13:03:35] jonno112: dminuoso: https://gist.github.com/jonlambert/ddd81f59c8d283564861effde34d9a68#file-every-key-removed-txt
[13:03:47] dminuoso: Yeah Gemfile please.
[13:04:05] jonno112: Doesn't Rails load from env when they're set?
[13:04:39] jonno112: I've added database.yml too
[13:04:39] dminuoso: jonno112: Rails uses the database.yml to figure out the database configuration.
[13:04:45] jonno112: solely that?
[13:04:51] dminuoso: jonno112: Yes.
[13:04:52] jonno112: http://guides.rubyonrails.org/configuring.html#configuring-a-database
[13:05:02] jonno112: "You can connect to the database by setting an environment variable ENV['DATABASE_URL'] or by using a configuration file called config/database.yml."
[13:05:10] dminuoso: I was not aware of this.
[13:05:11] jonno112: #RailsMagic
[13:05:16] dminuoso: I guess we have our answer then.
[13:05:40] jonno112: ahaha damn. That looks like it's it.
[13:05:45] dminuoso: See, this is why I stopped using rails magic.
[13:05:47] jonno112: I wasn't aware of that either, just reading the config.
[13:05:54] ferr: has joined #RubyOnRails
[13:05:54] jonno112: How did you manage that?
[13:06:25] dminuoso: jonno112: By no longer relying on the majority of auto-naming and magicguessing class names, routes, helpers, views,
[13:06:37] dminuoso: Its too much headache like you have just experienced if something doesnt work.
[13:06:44] jonno112: I wish I knew enough about Rails to avoid that
[13:06:51] jonno112: It's driving me insane
[13:07:08] ferr: has left #RubyOnRails: ()
[13:07:21] jonno112: I guess you have to know all the magic in order to avoid it, right?
[13:07:28] dminuoso: jonno112: Nope you dont.
[13:07:58] jonno112: Really? How so?
[13:08:05] dminuoso: jonno112: Good catch on that DATABASE_URL by the way. What made you look?
[13:08:56] dminuoso: jonno112: I just started developing in React for a while. Lack of two-way databindings and explicitly naming things and passing things was not cumbersome, it made it easy to trace errors and enable things like flow.
[13:09:25] dminuoso: jonno112: So based on that I started out with one subtle change in my views. No longer would I use instance variables and assume implicit renders, I rendered explicitly and always passed in locals.
[13:09:37] jonno112: I was suspicious of the magic haha. I'd remembered reading something about environment variables when I convinced the team I inherited the code from to use them (rather than hardcoding).
[13:09:46] dminuoso: From there I started to do this in other places too, so that the only magic I have is in the implementation of methods (and Im fine with that)
[13:10:05] dminuoso: But implicit behavior is not.
[13:10:14] jonno112: that sounds good. The whole tight coupling between ERB rendering and the request flow is driving me insane at the moment.
[13:10:22] jonno112: http request, I mean
[13:10:28] dminuoso: jonno112: I solved it by ditching ActionView entirely.
[13:10:45] jonno112: I wonder if I can convince these guys to do the same...
[13:11:13] dminuoso: trailblazers cells are a much more natural way to use views. the transition is so frustrating, because it forces you to figure out where things like helpers come from.
[13:11:25] dminuoso: No longer do you just "magically happen to have some `simple_form_for` method"
[13:11:35] jonno112: Wow that looks much better
[13:12:07] jonno112: (Full disclosure, I'm a React guy too!)
[13:12:17] jonno112: I'm primarily a Laravel/Node.js guy for the backend as of late
[13:12:23] dminuoso: jonno112: then you should like cells. they are kind of like react components
[13:12:46] jonno112: OK will 100% look into that
[13:12:49] dminuoso: (Except there's no virtual DOM, so cells produce HTML directly). For the most part its fine.
[13:12:58] dminuoso: (Or rather cells can produce anything)
[13:12:58] jonno112: does it handle erb rendering for you?
[13:13:07] dminuoso: jonno112: You can pick the template engine
[13:13:12] jonno112: and can you render to string?
[13:13:13] dminuoso: (if you want any)
[13:13:18] jonno112: like, an HTML string?
[13:13:23] dminuoso: jonno112: just like react components (SFCs), cells are just poros.
[13:13:45] dminuoso: You have some method `show` which is identical to reacts `render`
[13:13:48] jonno112: This looks great
[13:13:56] dminuoso: all it must produce is something stringlike..
[13:14:22] jonno112: This is awesome. Thanks so much for the recommendation. It looks like exactly the sort of thing I need.
[13:14:25] dminuoso: jonno112: they have their own `render` method, which renders a template. but unlike rails, `render` is really just "render that template, and give me back the result as a string"
[13:14:51] jonno112: I was tearing my hair out trying to use ERB with custom email stuff
[13:14:55] snickers: has joined #RubyOnRails
[13:15:38] jonno112: it was beyond me to understand why render insisted on outputting to the client haha
[13:15:43] dminuoso: jonno112: If you try out cells let me know. I have some good tips that will avoid sleepless nights. :P
[13:15:52] jonno112: dminuoso: Dude you're a lifesaver!
[13:15:57] dminuoso: (Because essentially you must debug rails to figure out why "rails magic" doesnt work)
[13:16:53] dminuoso: jonno112: https://gist.github.com/anonymous/46d043534a4b160248418466c1704134
[13:17:01] dminuoso: kind of like a react component :P
[13:17:16] jonno112: Yeah that looks so nice!
[13:17:27] dminuoso: And then outside guess how you use it:
[13:17:38] dminuoso: House::IconCell.new(some_model_instance).()
[13:17:50] dminuoso: or (use explicit .call(). or directly call .render())
[13:18:23] dminuoso: Its pretty much the equivalent of <IconCell model={model_instance} />
[13:21:31] dminuoso: In reality I should probably optimize this to directly return %Q(<i class="fa fa-question"></i>) etc because it's so frequently used.
[13:25:46] jonno112: ahh OK that makes sense
[13:26:04] dinoangelov: has joined #RubyOnRails
[13:27:05] dminuoso: jonno112: It also makes things like higher order cells trivial, because you can pass cells to cells, or have functions making cells.
[13:27:14] dminuoso: All the react-isms ready for use.
[13:27:19] jonno112: so it literally is just like React aha
[13:27:20] jonno112: that's cool
[13:27:34] jonno112: Have you ever checked out Laravel?
[13:27:45] dminuoso: jonno112: If you think about it, static page generation is reactive programming.
[13:28:28] dminuoso: You will not get me near PHP.
[13:28:42] jonno112: dminuoso: I'd recommend it. I know it's heresay recommending PHP, but the framework is beautifully written.
[13:28:52] jonno112: https://laravel.com/docs/5.5/blade#components-and-slots
[13:29:34] dminuoso: jonno112: Yesod, Spock and Phoenix are on my todo list.
[13:29:39] dminuoso: Probably going in that order too.
[13:29:56] jonno112: Personally, I struggle when maintaining large codebases with Ruby's lack of typing.
[13:30:13] dminuoso: that's why Yesod and Sprock are first in that list. :P
[13:30:19] jonno112: I know that's probably down to my usage, but I'm a stickler for types :P
[13:30:25] jonno112: I love TypeScript
[13:30:52] dminuoso: jonno112: You should try PureScript.
[13:31:03] dminuoso: TypeScript is really hard to read with a very non-concise syntax.
[13:31:30] dminuoso: Just be careful. HM is addictive.
[13:31:50] dminuoso: Rank-N Types are no joke.
[13:43:39] Technodrome: has joined #RubyOnRails
[13:54:33] iamarun: has joined #RubyOnRails
[13:55:20] LateralOctober: has joined #RubyOnRails
[13:58:48] mcr1: has joined #RubyOnRails
[13:59:37] TinkerTyper: has joined #RubyOnRails
[14:04:51] ahrs: has joined #RubyOnRails
[14:05:04] Tolnaiz: has joined #RubyOnRails
[14:07:33] workmad3: has joined #RubyOnRails
[14:14:44] Jameser: has joined #RubyOnRails
[14:19:06] mcr1: has joined #RubyOnRails
[14:27:06] TViernion: has joined #RubyOnRails
[14:37:31] safetypin: has joined #RubyOnRails
[14:39:10] jonno112: has joined #RubyOnRails
[15:08:56] chouhoulis: has joined #RubyOnRails
[15:15:18] fryguy: has joined #RubyOnRails
[15:18:42] safetypin: has joined #RubyOnRails
[15:19:09] ule: Why it's not recommended add something like: Foo.where(a: b) on a Rails view?
[15:19:55] ule: Just curious.. one dev just did this here
[15:20:13] TerianceVi: has joined #RubyOnRails
[15:20:45] fryguy: coupling the view to the model makes it harder to make changes later, it also makes it harder to test things, and it will lead to a higher incidence of bugs surrounding that code in the future.
[15:20:59] fryguy: it also precludes some forms of performance optimizations in the future
[15:23:54] ule: fryguy: the argument he gave is that if you need to remove a view, you don't need to touch controller to remove the instance variable
[15:25:01] ule: Idk, I still prefer stick with the Rails way moving queries to objects
[15:30:30] rfoust: has joined #RubyOnRails
[15:32:18] nicholasthegr8t: has joined #RubyOnRails
[15:35:34] planigan: has joined #RubyOnRails
[15:43:38] cschneid_: has joined #RubyOnRails
[15:48:55] troys: has joined #RubyOnRails
[16:06:08] dgsan: has joined #RubyOnRails
[16:06:44] dgsan: What does anybody use for log viewing/aggregation/searching?
[16:07:52] workmad3: has joined #RubyOnRails
[16:09:08] dminuoso: ule: It makes it easier to switch views or reuse code. I reckon that it also makes caching a lot easier.
[16:14:06] alfie: dgsan: uh... symlinks and grep >.>
[16:14:39] iamarun: has joined #RubyOnRails
[16:15:45] Technodrome: has joined #RubyOnRails
[16:16:37] jonno112: has joined #RubyOnRails
[16:17:57] Sylario: I should not have listened and stayed with RVM in staging
[16:18:40] Sylario: Is there a way to know what are the PATH seen by passenger ?
[16:19:58] drowze: has joined #RubyOnRails
[16:20:06] Sylario: My apache passenger has the following error : Message from application: cannot load such file -- bundler/setup (LoadError)
[16:20:37] Sylario: I followed this guide to install it : https://github.com/postmodern/chruby/wiki/Passenger
[16:21:59] dminuoso: sylario: Why are you using chruby?
[16:22:23] dminuoso: Do you actually need version switching on your staging server?
[16:22:26] Sylario: dminuoso: because I need ruby to be accessible?
[16:22:48] [Butch]: has joined #RubyOnRails
[16:22:52] dminuoso: chruby enables switching between multiple ruby versions installed in parallel.
[16:22:57] dminuoso: If you do not need this, you do not need chruby.
[16:23:09] Sylario: Without chruby I did not managed to make capistrano aware of ruby
[16:23:33] dminuoso: sylario: Yes, for this reason:
[16:23:45] dminuoso: http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/
[16:24:10] dminuoso: sylario: capistrano issues shell commands, including invoking ruby. For the command `ruby` to work, the executable has to be locatable in PATH.
[16:24:30] dminuoso: Now the question becomes, how is PATH set the way it is, and to understand that, you have to understand the various types of shell sessions.
[16:24:49] urk187: has joined #RubyOnRails
[16:24:51] dminuoso: sylario: I really do recommend you grok this stuff, because afterwards you should not need any "tutorial" or "code snippet". Instead you can address the problem.
[16:25:45] dminuoso: Not doing it, relies on the assumption that the myriad of plugins and scripts and snippets you collected "hopefully does the right thing". I prefer understanding how software interacts, and controlling it.
[16:27:01] mcr1: has joined #RubyOnRails
[16:31:14] iamarun: has joined #RubyOnRails
[16:35:07] mtkd: has joined #RubyOnRails
[16:37:53] cagomez: has joined #RubyOnRails
[16:45:57] iamarun: has joined #RubyOnRails
[16:47:53] cagomez: has joined #RubyOnRails
[16:48:54] bga57: has joined #RubyOnRails
[16:49:12] noob_on_rails: has joined #RubyOnRails
[16:49:35] Sylario: Is there any documentation on prod server
[16:50:21] Sylario: on how to install
[16:57:36] Saukk: has joined #RubyOnRails
[17:05:17] ule: Do you guys know how can I execute something only once before any "bundle exec rake test" ?
[17:05:40] ule: Any other way without overriding the rake test task?
[17:06:13] dminuoso: ule: you can enhance the `test` task
[17:06:27] dminuoso: Quite literally with Rake::Task['test'].enhance
[17:06:38] dminuoso: The syntax is just quirky as fuck.
[17:06:47] ule: awesome
[17:06:52] ule: I'm gonna give it a shot
[17:07:00] ule: Thanks dminuoso
[17:07:27] dminuoso: ule: If you want stuff to run before, you pass them as dependencies, if you want stuff to run afterwards, you do it in the block (dont ask why..)
[17:08:01] ule: I want to create some procedures before running my full test
[17:08:31] ule: Already created the rake task that loads this. Already have that hooked with Capistrano deploy as well
[17:08:31] dminuoso: ule: So this might be a long shot... but doesnt minitest have power for setting up things?
[17:08:51] ule: dminuoso: I only found out how to run things per test.
[17:09:49] dminuoso: ule: Ah well, guess I can just kick back and poke out my tongue. Rspec has this.
[17:10:18] ule: hold on.. I think I found something here (stackoverflow)
[17:10:28] dminuoso: ule: https://github.com/seattlerb/minitest/issues/61
[17:10:37] Papierkorb: has joined #RubyOnRails
[17:11:30] ule: before_suite
[17:11:37] ule: make sense, Let me try that
[17:11:42] dminuoso: ule: Read carefully.
[17:11:52] dminuoso: ule: They just talk about how awesome it would be to *have* a before_suite
[17:12:33] dminuoso: What can I say. It's as easy as before(:suite) in rspec.
[17:14:13] ule: oh man.. I miss rspec
[17:14:28] justinweiss: has joined #RubyOnRails
[17:15:44] helpa: has joined #RubyOnRails
[17:19:22] roshanavand: has joined #RubyOnRails
[17:21:03] dionysus69: has joined #RubyOnRails
[17:26:25] ule: dminuoso: http://www.itgo.me/a/x7647024356996547781/with-rails-using-minitest-how-can-i-set-up-rubocop-to-run-automatically-each-time-tests-are-run-with-rake
[17:26:53] ule: this guy is doing something similar, but he's basically running rubocop before any test using .enhence
[17:29:23] orbyt_: has joined #RubyOnRails
[17:31:23] dminuoso: ule: Well in this particular case enhance seems justified, as you're not trying to prepare the test suite.
[17:31:36] ule: agree with you
[17:31:46] ule: I'm going towards this direction
[17:33:35] ivanskie: has joined #RubyOnRails
[17:34:00] srinidhi: has joined #RubyOnRails
[17:38:26] bronson: has joined #RubyOnRails
[17:43:10] ule: it works but spitts all the db load on the screen
[17:43:37] one_zero: has joined #RubyOnRails
[17:48:33] melkor: has joined #RubyOnRails
[17:49:47] melkor: I am trying to install mysql2 gem with `mysql Ver 15.1 Distrib 10.2.9-MariaDB, for Linux (x86_64) using readline 5.1` but I get a segfault.
[17:50:52] dgsan: has joined #RubyOnRails
[17:51:52] dminuoso: melkor: File a bug report.
[17:52:03] dminuoso: melkor: After you make sure everything is up-to-date of course.
[17:52:18] dminuoso: melkor: Before you do, please make sure that you have no other native extensions running.
[17:52:33] melkor: "up to date"
[17:52:42] dminuoso: melkor: And `gem` itself segfaults?
[17:52:58] dminuoso: That sounds.. weird. Can you gist the command and entire output you have?
[17:53:13] melkor: Sorry, I got the gem to install, but now I get a segfault. Similar to other people in a thread.
[17:53:51] dminuoso: melkor: If things segfault (and you dont have any other native extension that could be in conflict), file a bug report.
[17:53:57] dminuoso: A segfault is always a bug.
[17:55:03] melkor: Ill check it out. I'm scrabbling a bit to get this far. Ill have to clean up tabs and maybe make a test case with just mysql2. I have other native extensions, but this appeared to be a known issue.
[17:56:01] melkor: I started from this thread. https://github.com/brianmario/mysql2/pull/880
[17:58:02] dminuoso: melkor: If you have other native extensions its generally impossible to say whats broken. If a native extension misbehaves, it could rewrite random memory and cause other things to crash.
[17:59:21] dminuoso: In very basic terms: a segfault happens when memory gets corrupted or not properly initialized. Since native extensions have free reign on your programs memory its impossible to point the finger at anythiing.
[18:08:13] workmad3: has joined #RubyOnRails
[18:11:59] dgsan: has joined #RubyOnRails
[18:12:25] hahuang65: has joined #RubyOnRails
[18:13:06] orbyt_: has joined #RubyOnRails
[18:24:39] Technodrome: has joined #RubyOnRails
[18:31:50] Exhiled: has joined #RubyOnRails
[18:33:48] dgsan: has joined #RubyOnRails
[18:38:42] Dimik: has joined #RubyOnRails
[18:47:16] Technodrome: has joined #RubyOnRails
[18:48:21] ShalokShalom: has joined #RubyOnRails
[19:05:52] DrYockel: has joined #RubyOnRails
[19:06:03] mcr1: has joined #RubyOnRails
[19:14:33] ur5us: has joined #RubyOnRails
[19:16:14] Hates_: has joined #RubyOnRails
[19:18:01] conta: has joined #RubyOnRails
[19:32:49] orbyt_: has joined #RubyOnRails
[19:44:33] zacts: has joined #RubyOnRails
[20:02:08] ur5us: has joined #RubyOnRails
[20:08:26] workmad3: has joined #RubyOnRails
[20:17:44] noob_on_rails: i have a problem with mailboxer generator :( getting these lines
[20:18:07] noob_on_rails: Running via Spring preloader in process 4146 [WARNING] Please install gem 'therubyracer' to use Less. Could not find generator 'mailboxer:install'. Maybe you meant 'bootstrap:install', 'ember:init' or 'mailer'
[20:18:28] noob_on_rails: with command rails g mailboxer:install ..
[20:20:49] NoGodDamnIdea: has joined #RubyOnRails
[20:21:46] GodFather: has joined #RubyOnRails
[20:30:57] orbyt_: has joined #RubyOnRails
[20:50:25] orbyt_: has joined #RubyOnRails
[20:54:10] Barrt: has joined #RubyOnRails
[21:12:09] dviola: has joined #RubyOnRails
[21:15:44] aiguuu: has joined #RubyOnRails
[21:25:14] Liothen: has joined #RubyOnRails
[21:26:10] peeja: has joined #RubyOnRails
[21:30:38] apeiros: has joined #RubyOnRails
[21:32:02] airdisa: has joined #RubyOnRails
[21:34:50] Technodrome: has joined #RubyOnRails
[21:39:09] arBmind: has joined #RubyOnRails
[21:51:53] melkor: has joined #RubyOnRails
[21:52:32] melkor: Is this channel logged?
[21:59:11] baweaver: See the channel topic
[22:02:53] melkor: Where does it say? In the rules it mention there are logs.
[22:03:34] baweaver: "Logs at http://goo.gl/uma9x"
[22:03:38] melkor: heh, my client cut it short. /topic says the logs.
[22:04:50] orbyt_: has joined #RubyOnRails
[22:05:47] melkor: How could I generate a project that just uses the mysql2 gem?
[22:08:35] melkor: Actually, Ill install a version of mariadb that worked before, and see if that solves the problem.
[22:08:45] workmad3: has joined #RubyOnRails
[22:09:24] noob_on_rails: is there anything wrong with this line ? q.results.map {|result| if result.is_a? Band ? @bands_arr << result : @albums_arr << result }
[22:09:47] baweaver: Have you tried running it?
[22:09:55] baweaver: Why are you using map?
[22:10:13] baweaver: You're mixing ternary and if
[22:10:13] noob_on_rails: *** SyntaxError Exception: (byebug):1: syntax error, unexpected '}', expecting keyword_then or ';' or '\n'
[22:10:18] conta: has joined #RubyOnRails
[22:10:54] baweaver: Read up on Enumerable: https://ruby-doc.org/core-2.4.2/Enumerable.html
[22:11:24] baweaver: and also read up on what a ternary operator is
[22:11:34] noob_on_rails: q.results.map {|result| result.is_a? Band ? @bands_arr << result : @albums_arr << result }
[22:11:40] noob_on_rails: that does work
[22:11:51] baweaver: It does, but that's a very odd use of map
[22:11:59] noob_on_rails: ok im all ears :O
[22:12:07] noob_on_rails: what should i use you say ?
[22:12:36] baweaver: @bands, @albums = q.results.partition { |r| r.is_a? Band }
[22:12:40] noob_on_rails: other times i've been able to mix ternary with if
[22:12:52] baweaver: your code is probably broken then
[22:13:12] noob_on_rails: baweaver: i didn't know what partition did actually
[22:13:30] noob_on_rails: ruby has many ways to do something tho no ? why is map a bad option here?
[22:13:31] baweaver: Either that or group_by: q.results.group_by(&:class)
[22:13:42] baweaver: What does map do?
[22:15:05] noob_on_rails: what do you mean? i use map to just map each item in the collection to a simple method
[22:15:15] noob_on_rails: and run it for each one
[22:15:20] baweaver: Explain to me what map does
[22:15:35] noob_on_rails: well , that's how i understand it atm
[22:15:41] noob_on_rails: takes each item of a collection
[22:15:50] noob_on_rails: and runs block of code for it
[22:15:58] baweaver: Then explain to me what you want to do there with bands and albums
[22:16:07] noob_on_rails: im getting an elastic response which is mixed
[22:16:08] baweaver: Technically yes, but each does that
[22:16:18] noob_on_rails: albums & bands models
[22:16:24] baweaver: what makes map different?
[22:16:38] baweaver: [1,2,3].map { |v| v * 2 }
[22:17:04] noob_on_rails: hm i haven't used each for so long
[22:17:20] noob_on_rails: i don't get it , i know they are pretty close as far as functionality goes
[22:17:42] baweaver: Map applies a function to each element of an array
[22:17:55] baweaver: [1,2,3].each { |v| v * 2 }
[22:18:03] baweaver: What does that return?
[22:18:33] shilon: has joined #RubyOnRails
[22:18:36] baweaver: Thing is your above function is completely reliant on side-effects to outside arrays, not the return value of the block
[22:18:37] noob_on_rails: hm i'd dare to say the same
[22:18:49] baweaver: each returns the original
[22:18:58] noob_on_rails: but each do |v|
[22:19:25] baweaver: they both return the original
[22:19:36] baweaver: do ... end and { ... } are the same thing
[22:20:21] Radar: GOOD MORNING
[22:20:28] baweaver: So using map and each interchangeably doesn't make much sense
[22:20:37] Radar: baweaver: { ... } is different to { ... } depending on what the ... is
[22:20:45] baweaver: each is used when you don't care about what the block returns
[22:20:49] baweaver: in the context of blocks
[22:21:11] noob_on_rails: so what you say is
[22:21:25] baweaver: map is used when you want to run a transformation to map from A to B
[22:21:31] noob_on_rails: [1,2,3].each { |v| puts v * 2 }
[22:21:34] dminuoso: noob_on_rails: #each is when you want to just trigger side effects for each. map is when you want to transform an array
[22:21:39] noob_on_rails: is still 2,4,6
[22:21:52] dminuoso: noob_on_rails: the point is the return value of that .each call.
[22:21:58] baweaver: It would return [1,2,3]
[22:22:06] dminuoso: #each is for causing side effects, #map is for transforming.
[22:22:09] noob_on_rails: but it would output 2,4,6
[22:22:21] baweaver: Does it? (hint: no)
[22:22:23] noob_on_rails: dminuoso: as saying one is destructive and one is not ?
[22:22:29] dminuoso: noob_on_rails: Nope..
[22:22:31] baweaver: puts will output it to the screen as text
[22:22:31] centrx: has joined #RubyOnRails
[22:22:35] noob_on_rails: ok it's only the return i get it
[22:22:36] dminuoso: map is quite non-destructive.
[22:22:37] baweaver: puts itself returns nil
[22:22:46] dminuoso: map gives a new but transformed array back
[22:22:50] noob_on_rails: baweaver: that's what im saying
[22:22:51] dminuoso: each gives you the old array back
[22:22:52] baweaver: Open up irb and try it out
[22:22:54] noob_on_rails: it'll print it if u will
[22:23:00] noob_on_rails: but i do get that if you do
[22:23:01] baweaver: that's not a return, that's a side effect
[22:23:10] dminuoso: baweaver: See? We need to explain functors!
[22:23:12] noob_on_rails: a = [1,2,3]... , a will still be 1,2,3
[22:23:48] shilon: hello everyone, I have devise user and another one non devise. The devise user I want to connect to multiple omniauths and the non devise I want to use just facebook. For some reason I can’t use devise and omniauth config at the same time. Anyone experienced this issue?
[22:23:49] baweaver: depends on what you do to it
[22:24:13] noob_on_rails: ok , still , why is map a bad choice
[22:24:22] baweaver: Can't say I've played with omniauth before, so not sure
[22:24:30] noob_on_rails: i mean , it could be a bad choice compared to a better/cleaner one
[22:24:33] baweaver: noob_on_rails: what is your code doing?
[22:24:40] dminuoso: noob_on_rails: map is if you want to calculate a new array based on an old array.
[22:24:46] baweaver: It's splitting based on class name
[22:24:52] noob_on_rails: dminuoso: that's what im trying to do
[22:25:03] baweaver: you're creating multiple arrays
[22:25:03] dminuoso: noob_on_rails: No.
[22:25:26] baweaver: by using side effects on external arrays
[22:25:52] baweaver: a = []; b = []; results.each { |v| v.is_a?(A) ? a.push(v) : b.push(v) }
[22:25:56] shilon: baweaver: can I have both users with devise?
[22:25:58] baweaver: You mutate a or b
[22:26:07] baweaver: Not sure Shilon
[22:26:13] shilon: ok thanks. :)
[22:26:15] Radar: Shilon: You are number TWO in the queue. Please hold.
[22:26:32] Radar: Shilon: What happens when you try to do that?
[22:26:36] baweaver: Oooo, morning Radar :P
[22:26:48] Radar: yes it is i
[22:26:53] baweaver: noob_on_rails: So you don't care about what map returns
[22:26:59] baweaver: you care about the side effects of the block
[22:27:09] noob_on_rails: oh now i get it
[22:27:16] noob_on_rails: ok , yea now i get what you say
[22:27:21] Radar: noob_on_rails: baweaver's right. It's typically bad form to mutate other objects while iterating through an object.
[22:27:25] baweaver: hence using map is an odd choice there
[22:27:26] baweaver: each works just as well
[22:27:27] baweaver: but partition is a better function to use
[22:27:33] Radar: His suggestion to use partition is sensible
[22:27:39] noob_on_rails: you mean , if you're about to use a map , do it to use the return feature as well
[22:27:40] baweaver: group_by if you have multiple different ones
[22:27:49] baweaver: basically yes
[22:27:50] Radar: [09:12:36] <baweaver> @bands, @albums = q.results.partition { |r| r.is_a? Band }
[22:28:16] noob_on_rails: ok i actually didn't even know this syntax , quite interesting
[22:28:23] shilon: Radar: the non devise user stops connecting to facebook when I try to add omniauthable to the devise user.
[22:28:40] baweaver: noob_on_rails: Read through the Enumerable documentation
[22:28:44] Radar: noob_on_rails: Your homework: https://ruby-doc.org/core-2.4.0/Enumerable.html
[22:28:48] baweaver: It's going to be a huge part of learning Ruby
[22:28:57] baweaver: and one of if not the most powerful tool in it
[22:29:09] Radar: noob_on_rails: I sent out a junior coding test a few months about and it was _mostly_ about Enumerable methods. They're really useful to know.
[22:31:51] noob_on_rails: baweaver: will do
[22:31:51] noob_on_rails: Radar: you said : It's typically bad form to mutate other objects while iterating through an object.
[22:31:51] noob_on_rails: in simple words , you wouldnt change a collection per say
[22:31:51] noob_on_rails: inside an iteration of another collection
[22:31:52] noob_on_rails: only use a method that returns the final collection?
[22:31:53] noob_on_rails: and then pass it to the object you want to change
[22:31:56] noob_on_rails: baweaver: if you got what Radar said , do i get it?
[22:32:45] baweaver: Look for a method which does no mutation if possible
[22:33:25] baweaver: and avoid changing variables unless you absolutely have to
[22:33:26] baweaver: makes it a lot easier to change code later.
[22:33:45] CBebop: has joined #RubyOnRails
[22:34:04] noob_on_rails: thanks a lot guys :D
[22:35:46] noob_on_rails: im trying to learn better coding patterns as i move on , so this is really helpful!
[22:36:22] baweaver: ladies too ;)
[22:38:58] ankhers: has joined #RubyOnRails
[22:40:14] orbyt_: has joined #RubyOnRails
[22:42:52] snickers: has joined #RubyOnRails
[22:43:04] blindMoe: has joined #RubyOnRails
[22:43:47] blindMoe: I have an api endpoint that gets hit and basically just returns some data stored in the session for that user. It works great in all browsers with the exception of Safari. In Safari session.id is always nil. Has anyone ran into this before? I am at a loss
[22:44:06] blindMoe: was wondering if maybe Safari was not storing cookies for some reason but I don't see any error in the console and the cookie exists
[22:45:05] blindMoe: hrmm actually it looks like the cookie is empty in safari
[22:45:12] blindMoe: no idea what would cause that
[22:48:24] blindMoe: arg I think it is because it is in an iframe.. wtf safari
[22:49:51] tenderlove: has joined #RubyOnRails
[22:53:20] maxmanders: has joined #RubyOnRails
[22:58:51] orbyt_: has joined #RubyOnRails
[23:15:28] xlegoman: has joined #RubyOnRails
[23:18:12] [Butch]: has joined #RubyOnRails
[23:23:18] nachoman: has joined #RubyOnRails
[23:25:40] nachoman: can two asset files with the same name be referenced from asset_path so I can use both from views without changing their names?
[23:26:10] Radar: nachoman: where are these assets with the same name?
[23:26:21] Radar: nachoman: what are their paths relative to your application's root?
[23:27:09] nachoman: app/assets/global/img/foo.jpg app/assets/layouts/img/foo.jpg
[23:27:35] Radar: Those two assets are at different paths. So you could refer to them as global/img/foo.jpg and layouts/img/foo.jpg.
[23:27:42] helpa: Next question, please!
[23:29:41] uks: has joined #RubyOnRails
[23:31:05] nachoman: thank you Radar
[23:34:17] mikecmpbll: has joined #RubyOnRails
[23:34:56] Technodrome: has joined #RubyOnRails
[23:37:12] noob_on_rails: anyone here has any experience with searchkick?
[23:37:18] helpa: 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.
[23:38:17] noob_on_rails: true , ahh well im querying elastic with searchkick , i have indexed my stuff but i want an associated model to come back
[23:38:25] noob_on_rails: so When im going for a Band i want the album too
[23:38:58] noob_on_rails: when i do the query and go q.results , i see in the console that 2 queries happen to the DB , one for the band and the other for the corresponding albums
[23:39:05] noob_on_rails: but q.results has only the bands in it :(
[23:39:58] noob_on_rails: q = Searchkick.search("Metallica", index_name: [Band],includes: %i[albums] , model_includes: {Band=>[:albums]}, fields: [:name], match: :word_start)
[23:40:36] noob_on_rails: this is how my query looks like atm , but i've played with includes a lot , so i've tried model_including albums => bands or straight including etc
[23:41:37] noob_on_rails: why doesn't it show the albums if the query happens alright ?
[23:42:06] noob_on_rails: also i've populated my search_data in the has_many part
[23:48:22] rfoust: has joined #RubyOnRails
[23:48:59] Radar: noob_on_rails: https://stackoverflow.com/questions/31046428/rails-searchkick-elasticsearch-has-many-and-belongs-to-associations
[23:49:07] Radar: Guessing you didn't do that?
[23:49:23] Radar: Because I don't see code for that atm
[23:49:42] noob_on_rails: done it :( let me gist
[23:51:33] noob_on_rails: https://gist.github.com/frcake/c6ae6795f4911f0411b602f78343df9c
[23:51:41] noob_on_rails: there's a stupid duplicate db record atm
[23:51:51] noob_on_rails: but one of the records has valid albums
[23:52:21] noob_on_rails: but i think that include %i[albums] should trigger the second query, and not the actual elastic results
[23:52:50] noob_on_rails: still , weirdly enough the albums are not included anywhere i can think of
[23:53:51] noob_on_rails: hmm maybe i should only use "searchkick" instead of going for a single field on the model
[23:56:08] nachoman: Radar: when I try to reference an assset like asset_path('global/img/foo.jpg') doesn't work, it says that is not present in the asset pipeline, but when I import it with asset asset_path('img/foo.jpg') it works. Is there another way to specify absolute path (including ancestor directory) using asset_path or another helper?