#RubyOnRails - 22 May 2018
« Back 1 day Forward 1 day »
[00:16:25] Skull0Inc: Ok so - apparently its a turbolinks issue. where <meta name="turbolinks-visit-control" content="reload"> should be placed in <head> to force reload. just in case anyone comes across it.
[01:25:39] mices: how do i make a meta tag in my view to render this html <meta http-equiv="X-UA-Compatible" content="IE=edge" />
[01:55:07] creature: mices: Presuming you'd want that on every page, you could put it in app/views/layouts/application.html.erb.
[02:09:39] havenwood: puts tag :meta, 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' #>> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
[02:22:46] mices: if the script contains: `return res.token;` how do i see if token is success in my controller? ... if token.success?
[05:48:12] quazimodo: lets say we have a sufficiently large db that we want to denormalize some aggergate data into differente organisations root accounts, but the procedure to do so is fairly complex and already coded in rails. One way is for us to call this operation in rails each place we need to, another is to have the postgres db trigger on some rules and run some sql query to do the same thing
[05:48:49] quazimodo: my question is, can the postgresdb trigger a callback on the rails app, conceptually like a webhook, to cause the rails app to do that operation that's already built & tested?
[05:49:40] quazimodo: this idea could also push a job into a sidekiq queue to do the thing, which is probably what I'd want to happen
[06:22:35] tomoyuki28jp: Can anybody answer this question? https://stackoverflow.com/questions/50460459/mountable-engine-capybara-with-rspec-main-app-helpers?noredirect=1#comment87934347_50460459
[06:36:27] lupine: I'd probably prefer to update a column to show stale data and poll those on a cron
[09:52:00] NL3limin4t0r: Quick question, I'm looking through the formtastic documentation for a way to set `required: false` for every field in the form. Instead of doing that per field. Does anybody know if there is such a setting?
[10:13:42] dminuoso: samosaphile: One of the main issues that web development has had is the emergence of dumb technologies. The bar of quality software has been massively lowered.
[10:17:19] dminuoso: If you just go through https://www.npmjs.com/browse/depended about 90% of those packages are not packages solving software problems
[10:17:36] dminuoso: they are packages fixing core deficiencies of the language, browsers, JS implementations in browsers, etc
[10:32:32] samosaphile: IMO, one of reason(s) why there is so much money in web dev stuff now is because of the emergence of technologies like nodejs which enable more powerful like web apps.
[10:32:44] samosaphile: If you know how to deploy web app's like on cloud (e.g. AWS, GCP, etc) you're basically doing devops stuff almost. Atm right now, there is allot of money for knowing how to setup, config web apps in containers. Yes, if you just know 1997 HTML no one is going to care, just in the same way knowing 1997 python will get you nowhere.
[10:32:55] samosaphile: If you stay stagnant in any field you'll get nowhere (especially in tech field) but it is a stepping stone. Just like you can't break into ML / DL field without knowing the foundations of python. Knowing the foundations of web dev / JS help enable you to understand devops / cloud. (because 90% of the stuff being deployed on AWS is stuff like JS web apps and mobile apps)
[10:36:07] samosaphile: you can hate web dev stuff all you want but the future is all about collaboration and openness
[10:37:14] samosaphile: dev stuff didn't really get big or mainstream until stuff like github came around imo
[10:38:23] dminuoso: Node just allowed dumb web devs to solve programming tasks we've had 50 years worth of programming languages already without extra training
[10:40:40] tbuehlmann: I'd be careful with this elitist thinking. it's for a reason we build frameworks and libraries so you don't _have_ to know everything, opening the filed for a larger audience with all kinds of backgrounds and by far not all being experts or good at it
[10:44:19] dminuoso: tbuehlmann: The JS world tries to build stacks of frameworks and libraries to make the language fit to a problem domain.
[10:47:10] tbuehlmann: "they are packages fixing core deficiencies of the language" - that's what I really dislike about js, it's missing a lot of core functionality that I like from other languages
[10:55:14] dminuoso: samosaphile: Erlang is one of the primary languages in telecommunications and networking areas.
[10:55:41] dminuoso: It's favoured for immutable data and what is the most mature multi machine concurrency solution with things like hot patching capabilities.
[10:59:08] dminuoso: samosaphile: OTP brings things like extremely cheap threads, actor model concurrency, hot/live module/code patching, high fault tolerance and other things.
[11:04:41] samosaphile: all those features that erlang has may sound nice and all, but where is the industry mass adoption
[11:09:28] samosaphile: the features i want the problems am trying to solve don't see how stuff like erlang or haskell would help at all
[11:20:36] samosaphile: but lol dminuoso i don't know how you ended up here in rails in the first place with your hate of web xD .. surprised you're in ruby ... instead of like rust or somewhere
[11:21:53] samosaphile: anyways, my point was just to show that there is money in web dev stuff. think i proved this point. so mission accomplished.
[11:25:42] samosaphile: but i suppose there is money in anything if you're good at it... just that you said avg. salary in us was 60k / yr. yes, it is, but it can easily be doubled switching to learning devops stuff. i guess you could say the same about erlang or haskell, but i just don't know or am aware even of erlang/haskell being popular in cloud to deploy stuff on aws and stuff
[11:27:34] samosaphile: altho im not even sure why i keep mentioning devops as it seems dead boring and something only companies care about
[11:30:12] dionysus69: I think anything is possible in any language, the question is, is it worth your time?
[11:31:50] NL3limin4t0r: It doesn't. The question is what is: what problem are you trying to solve and what language makes that the most easy to do?
[11:55:24] dminuoso: The main reason we still use Ruby is actually just because we have a Ruby codebase and not yet decided to deprecate things for replacement.
[12:25:50] dionysus69: Never realized you hated ruby, unless this is another instance of your dark sarcasm ^.^
[12:29:11] dminuoso: dionysus69: Im currently writing a RADIUS Server. In my last programming session I wrote about 400 lines straight off the bat. The second it type checked, the code was bug free (as far as my testsuite can detect). This happens regularly.
[12:29:24] dminuoso: It gives so much more confidence than this "write a line of ruby code, run it and pray it works"
[12:30:39] dionysus69: If you can test haskell code so efficiently, why can't you test ruby code the same way?
[12:31:36] dminuoso: Strictly speaking its not a Ruby issue, because any language that doesn't have any type system suffers from thijs.
[12:31:53] dionysus69: I rarely get problems with types :P If I do, I just run once and see what it returns and there I go xD
[12:33:23] dionysus69: haskell in my mind is lower level language, whatever it offers, you can say same about c# or java too then :D
[12:35:37] dionysus69: haha, anyways most of the programming I have done by now is in ruby so, I dont even remember last time I used types in java
[12:35:41] dminuoso: dionysus69: https://gist.github.com/dminuoso/c69dea6552207ea77928346c76e4eea1 this is a type level description of one of my API endpoints. It's a raw type.
[12:37:49] dminuoso: dionysus69: `"users" :> Capture "name" String :> Get '[JSON] Account` is a _type_ that describes an API endpoint `/users/:name` that accepts JSON for content-type
[12:38:28] dminuoso: dionysus69: These types automatically flow through the program and ensure that each request handler for each endpoint knows about the _exact_ possible types.
[12:39:23] dminuoso: It lives entirely at the type level and is used by the compiler to statically verify certain assumptions about my program.
[12:40:40] dionysus69: still vague though, which exact problem is being tackled, if let's say I had same thing in Rails
[12:41:58] dminuoso: dionysus69: Prove to me that your controller treats `id` as a string, and that it _always_ produces a JSONfied Account
[12:42:14] dminuoso: dionysus69: The second I save my file, I have that guarantee. I dont need to write a test for it.
[12:42:52] dminuoso: dionysus69: The second I make a modification to my API type description, say because I no longer produce an Account object, but maybe some (Account, Identification) pair, Im instantly shown every piece of code that conflicts with that change.
[12:43:11] dionysus69: well I don't know, if you are building an app for a martian probe maybe it needs to be proven, but in my experience, I can safely assume the expected behavior
[12:43:41] dminuoso: dionysus69: I rarely specify types. Inference guarantees they flow through my program.
[12:46:30] dminuoso: they are no silver bullets in the end, but there's no value in _not_ having them except for some exotic use cases
[12:46:33] dionysus69: well, even software like ssl had bugs so, until human is the programmer, bugs will always exist
[12:46:54] dminuoso: dionysus69: Well you can take this to the extremes: Coq allows you to write _verifiably_ correct programs
[12:48:37] dionysus69: btw, if you are good at Haskell you should try work with Cardano team, I heard they hired a guy who created Haskell :D
[12:49:23] dminuoso: Far from it. Been at it for maybe 6 months. But Im comfortable enough with it to solve most daily problems with. :)
[13:22:14] dminuoso: dionysus69: In the end you already do the "program behavior" that tests verify in your head already. It's the menality "When I call `.foo()` I get something back that responds to `.bar()`, or maybe even more accurately "I get a String back". There's very little value in refusing to have the implementation check that things will work out.
[13:22:49] dminuoso: You have to think these thoughts to program anyway. I mean you don't just randomly .openSocket().readBytes().sendToDatabase() and pray these methods exist and do what you want.
[13:25:30] dminuoso: dionysus69: If Rubocop becomes so essential and useful, why not somehow glue it into the language itself. ;)
[13:26:31] dminuoso: What value do you have from _not_ having invariants checked across your entire code?
[13:27:18] dminuoso: dionysus69: Before you answer this, let me give you the most definite and accepted definition of a type system in type theory
[13:27:59] dminuoso: dionysus69: "A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."
[13:28:14] dionysus69: I think people have right to commit suicide if they want to, no need to have compiler check before someone decides to :D
[13:29:13] context: dionysus69: and with ruby you can do just that. if you want to shoot yourself in the foot by calling functions that dont exist use a language that lets you.
[13:29:17] dionysus69: but obviously not enough rubyists think that way, because by now core team would have implemented rubocop into the language perhaps
[13:29:22] dminuoso: It usually boils down to "type systems sometimes filter out good programs", which sucks. If you hit one of those cases then fine, a type system might be in the way. But sufficiently advanced type systems are extremely flexible already.
[13:29:58] dminuoso: So it's the "it looks wrong but its not" case. Those happen to be fairly rare from what I can observe
[13:30:00] dionysus69: well and I do, I just know what I am calling :D, I always run the code once at least before delploying, or 100 times if I am not sure
[17:50:42] RougeR: heya quick xpost from #ruby, i could do with some help or a guide on how to work with data in a join table (has many :through)
[18:57:16] charlielor: I tried rails console and I got this error: .rvm/gems/ruby-2.4.4/gems/activerecord-5.2.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `Connection' for ActiveRecord::Base:Class (NoMethodError)
[19:10:46] fryguy: charlielor: well, where are you calling `Connection`, which looks like it's capitalized and shouldn't be
[19:14:22] charlielor: the connection.rb class declaration: class Connection < ActionCable::Connection::Base
[19:14:28] MrCrackPotBuilde: hi i know this is js channel but i have a problem with turbo links and js. https://gist.github.com/scope2229/6ea4d5d2a42f48f1af1538b580359a68 in this file the script element is created every time i reload the page is there a way to turn that into an if to
[19:16:24] charlielor: fryguy: oh, I found another place where it reference the ‘Connection’ class and that is in the application.rb. ActiveRecord::Base.Connection
[19:18:00] charlielor: I commented out this line ActiveRecord::Base.Connection and rails console works now.
[19:18:00] fryguy: MrCrackPotBuilde: probably stop using turbolinks unless you have a good reason to
[19:19:46] MrCrackPotBuilde: i spent all week getting the map to show in the first place when i switch links
[19:21:58] MrCrackPotBuilde: but to do this im at a loss would i just use a getelementbytag and select the body then check is script is there but that will always come back as true
[19:22:56] MrCrackPotBuilde: always comes back because of the whole rails doesnt reload a page it jus changes the content. also my .css once compiled to html becomes <script>
[19:27:19] MrCrackPotBuilde: i also cant check if the specific script is loaded as its that script that is needed in the first place
[19:34:07] MrCrackPotBuilde: by the looks of it res is a list of some sort with a member named token
[19:40:51] MrCrackPotBuilde: if you have used a paypal gem check inside github see what res.token is
[19:43:31] mices: i dunno i haven't looked at this closely enough yet, i dunno if i should use this or the paypal-ruby-sdk
[19:47:21] RougeR: i need my rails has_many through associations looking at im getting unitialized constant
[19:50:08] mices: join tables have to be named using singular for both tables example "person_address"
[19:51:41] RougeR: https://github.com/CodePint/SendRoute/blob/master/db/migrate/20180502150841_create_memberships.rb
[19:52:40] MrCrackPotBuilde: mices before you ever use a new gem always take a look through especially a third party gem
[19:53:21] MrCrackPotBuilde: a lot of the time they may either a need tweeking b you creating your own gem instead c just works for basic and or overkill functionallity \
[19:54:18] MrCrackPotBuilde: theres been many times ive found a gem for a third party api but it just doesnt do or does too much of what i want
[19:58:17] MrCrackPotBuilde: in the controller you would have def view end def save end def create end etc
[19:59:16] MrCrackPotBuilde: as to which gym the user is from that would be down to how you have set up the database and how you set up the logic of the model
[20:00:22] MrCrackPotBuilde: you would on initial creation have a input field asking which gym the user is a member of
[20:03:31] jarnalyrkar: (Just wanting to say that as a rails beginner I'm following this conversation closely, and you MrCrackPotBuilde are now my hero :)D
[20:04:10] mices: RougeR you can create an object representing the groups users and then just add a list of @users to it with @membership.users + @users
[20:07:01] mices: RougeR then you can create a checkbox list of users and check all the users you wanna add and click submit once
[20:07:52] MrCrackPotBuilde: https://stackoverflow.com/questions/7606124/using-join-tables-in-ruby-on-rails?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
[20:08:07] MrCrackPotBuilde: heres a reference i used a while back for when i created a app for spas
[20:09:17] mices: the names of the join tables in has_many_through have to be singular for both tables and in alphabetical order
[20:13:34] MrCrackPotBuilde: basically my js file controls the lot no scripts anywhere and in contact just div id map
[20:15:49] MrCrackPotBuilde: which removed the error of the map only loading when the page was refreshed
[20:16:20] MrCrackPotBuilde: now though if i go from contact to home to contact i get the error two instances of api
[20:17:24] MrCrackPotBuilde: since the only place in the entire app the script created is the js file my conclusion is turbolinks when changing page is adding a second script then after moving again removing so i always have two scripts
[20:18:42] RougeR: could you add an if statement to not run the script if there is already an isntance running
[20:19:15] MrCrackPotBuilde: no because im too stupid to know how to do it due to the fact i have so many script elements becaue of turbolinks
[20:19:50] mices: MrCrackPotBuilde in these examples i should replace return with something= i think
[20:20:32] MrCrackPotBuilde: i thought about first looking for scripts but that failed because css is also script then i thought about looking for the exact script but that failed after link clicking
[20:22:19] RougeR: i hope you get it sorted MrCrackPotBuilde. sorry if im a bit short tempered. Im working on my own to learn this and ive been working for hours.
[20:24:54] MrCrackPotBuilde: try remote work and if you are no good as a designer try to find someone who is
[20:25:13] MrCrackPotBuilde: i started out like that and told my friend also starting out i can only pay if i sell
[20:25:22] RougeR: i am soo not a designer haha, i cant stand front end work. I want to work contract/remote eventually
[20:27:56] RougeR: im guna take a break, then get the CRUD and validaions for membership table setup. Ive brought a couse on udemy for CSS/JS going to try learn it even though i hate it
[20:28:25] RougeR: i just dislike how overcomplicated and fractured front end is...why are there seven million js/css frameworks
[20:28:45] MrCrackPotBuilde: when i first learn js css and html way back i actually called companies up asking what they wanted then learnt it hahah
[20:30:36] RougeR: MrCrackPotBuilde: aye im going too. although jobs im looking for are backend/devops
[20:30:53] MrCrackPotBuilde: really i worked on a element yesterday that just 4 cirlces its over 800 lines of css or 20 scss
[20:41:51] MrCrackPotBuilde: so just before the insert of the script i check to see if google has been defined then if it has run initMap if not insert the script that bloody simple but took over 12 hours
[20:50:38] darkhanb: I'm i18n-ing the Rails app and according to these plural rules Latvian, Prussian languages use :zero plural form for 10-20
[20:50:39] darkhanb: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#Cardinal-Integer
[21:06:06] RougeR: trying to understand why i cant access attributes on a has many through join table
[21:07:57] jarnalyrkar: hmm, I don't have any relations of that kind in my current project, so I wouldn't know :/
[21:08:08] jarnalyrkar: http://theartandscienceofruby.com/2016/01/13/confused-about-has_many-through-associations-heres-what-they-look-like-in-the-database/
[21:20:17] RougeR: was trying to call active record methods on an array. hopped in a pry debugger n got it
[21:42:56] amperry: Hi folks, in addition to STI, how can you model OO-style inheritance between tables with Rails? (I might be fine with STI alone, but I'm looking for options.)
[22:04:36] regedit: I have a Messages model and ContactNumber model. I'd like to add ContactNumber.opted_out_message_id column which should refer to a single Messages record
[22:04:48] regedit: The idea being i need to record whether a ContactNumber is considered "opted out", and if so which Message record is the one that "opted out" the ContactNumber
[22:05:55] regedit: i'm fumbling around not sure how to achieve this, messing with belongs_to / has_one, add_reference with custom column name, no foreign keys etc...
[22:40:20] dionysus69: so you are saying I should stop using activestorage right now ? :D I just spent half an hour trying to download and attach to activestorage
[22:41:16] dionysus69: where.first_or_create ..... ..... do |user| user.avatar.attach(auth.info.image) end
[22:42:04] dionysus69: so how do I download file with auth.info.image url and convert it into file object, all that inline
[22:43:01] Radar: I'd use a HTTP library (like http.rb), download the file and then save it to a tmp directory. Then I would attach that file using AStor's methods
[22:45:41] amperry: is there a method or command in the rails console to list an object/model's associations?
[22:58:08] amperry: does it make sense for one model to 'has_many' another model, and the other model to 'has_many' that model, without either of them 'has_and_belongs_to_many'? I'm tempted to try something, but the idea sounds dumb to me.
[23:02:04] dionysus69: whatever you are saying doesn't make sense because non of them have a reference id
[23:03:21] Radar: amperry: Can you talk in more absolute terms? Perhaps using the names of your models?
[23:04:17] amperry: dionysus69: yeah. right now I have a have a model, Placement, which has_many Residents, which (most of the time) act like they belong_to that one Placement. But a Resident can move, and get a new Placement. Placement is a container for everything rental related, including Lease, Apt, Residents, and Ledger.
[23:05:26] amperry: they can also sign a Lease before moving, or renew a Lease (which is not really 'renewing' it, but it's really signing a new one), so they can still be in their current Placement while awaiting the move to the new one.
[23:05:41] dionysus69: Placement has many residents through placement_residents join table, that is generic and works in all cases
[23:06:06] dionysus69: but you can optimize it by coming up with better model names :D placement seems general so it will be hard to optimize that
[23:07:56] amperry: Placement is a container; I would have gone with Lease, but a Resident can be associated with an Apt by placing a deposit on it before they actually sign. This is based on an old app that didn't even have a Lease table, but instead (a) listed everybody on the Lease as a single resident, and (b) created a new Resident every time they moved or re-signed.
[23:09:33] amperry: so I needed a way to group people together and conditionally associate them with an Apt, even if they don't sign a Lease, because a non-refundable deposit fee is associated with the Apt and I need to account for that.
[23:11:56] amperry: 19/20 times or more, I'll be querying their present location; but there are some reports and some odd processes that need to see their past locations (including two roommates who go their separate ways) and possible future/prospective one.