#RubyOnRails - 12 September 2018
« Back 1 day Forward 1 day »
[00:51:12] MasterAsia: It looks like there is no difference between a sign & encrypted cookie from a session (that uses the cookiestore)
[00:59:58] advorak: hi there. How do I add a 'get' to a resource from outside the resource definition? My code is here: https://gist.github.com/advorak/e2caf673189ffd3d93cf3b06ab23b19c
[01:22:41] NeoHamled: advorak: would this work? https://gist.github.com/Hamled/29cd526eb6d1d152338692d932846244
[01:44:36] advorak: neohamled, I'm probably trying to do something that isn't liked by rails/rest by omitting the "/definitions" portion of the url, correct?
[01:46:52] NeoHamled: I'm not sure I have enough information to say if it's restful or not, if definitions, flashcards, multichoice, and type are all separate resources then they shouldn't be nested, so your approach is correct in that regard
[01:48:24] NeoHamled: and if you want all of the actions to be within the definitions controller, that's probably not following Rails' conventions, but it should be fine. I would do: https://gist.github.com/Hamled/29cd526eb6d1d152338692d932846244 possibly?
[01:53:05] NeoHamled: oh the link is the same but I've updated the file contents, sorry if that was confusing
[01:57:26] advorak: I use rails intermittently to solve problems .. I perfect routes .. then I don't use rails .. then I forget about them .. and then I perfect them again :-)
[02:22:57] samort7: I have a really noobish question about how forms work: https://codeshare.io/2BjAQK
[02:25:33] NeoHamled: it allows form_for to generate a form with certain things customized to the model
[02:25:45] sevenseacat: when you submit the form, all that gets passed to the server is the data that was on the form - you can see that in your development.log
[02:26:19] samort7: sevenseacat: right - form_for creates a hash called user that contains all the entries, right?
[02:26:52] sevenseacat: well in this case you have fields for name, email, password and password confirmation so thatswhat you get in your params
[02:28:44] samort7: ok, and then the form passes that data back to create, where it calls the user_params method to filter it, and passes those filter results to a new user object
[02:29:44] samort7: I guess I am still trying to understand what NeoHamled was saying - how the @user variable in new interacts with the form
[02:30:38] sevenseacat: rails will do things like pull the values of fields for the values of the form elements
[02:30:39] i8igmac: im not sure if i should use ace-rails-ap gem or the original git repo github.com/ajaxorg/ace-builds
[02:30:58] sevenseacat: eg. if you set the @user.email in the new action, it would be prefilled on the form
[02:31:27] sevenseacat: some of it is just niceness so the same form can easily be used for new/create/edit/update
[02:31:57] NeoHamled: it can inspect the @user object and figure out if you are creating a new one or updating an existing one
[02:32:25] sevenseacat: aye, and set the URL that the form submits to appropriately (if following rails resourceful conventions)
[02:37:50] sevenseacat: if you had something like a form for a user to edit their profile - you could just do form_for @user and all of the form fields would be filled out with the data from that user
[02:50:00] i8igmac: could some one provide help with ace code editor. i hope to run this editor and make changes to the currently running rails project with a tree source view of the directory structure
[03:20:09] i8igmac: are there any ide's that i can install in my rails app to provide remote access to the project from a android phone
[05:12:15] Sonja: Does Rails have a method that minifies or compresses an HTML file, and can I use it in Ruby code independently of Rails?
[06:31:05] dionysus69: Hey all, I have heard in past that modifying params hash in place was not gonna be possible soon, I don't know if that soon is already here but anyway I want to do the following, I am passing some parent model attribute instead of an ID, using IDs in my scenario doesnt make sense, so I want to select IDs before I insert params hash in Model.new, so how do I go about it?
[07:32:56] fourcolors: Does anyone know a good way to duplicate an ActiveRecord Model that has an ActiveStorage attachment associated with it?
[12:50:41] cpinto: Can anyone give me some pointers to improve this code? https://gist.github.com/cpinto/b01fc9e9a7b6f41ee5815d2e2ca4e9f0
[12:51:18] cpinto: I'm looking to load the attachments and the blobs with one query. the current implementation hits the database twice.
[15:47:32] rikkipitt: hey folks, i'm using a simpledelegator for a "Post", what's the best way to decorate child comments is a similar fashion?
[16:18:27] za1b1tsu: with nested_attributes for children of a child I can update and delete, but I cannot create
[16:20:54] brandoncordell: I'm updating our application to Rails 5.2 and I'm having some issues. Running bin/update or any rails commands all output the two following messages before executing. The first message is: "This method is not allowed with this Ruby version. current: 2.5.1, allowed version: < 2.5.0"
[16:21:38] brandoncordell: I searched google and the only thing that came up was a source file in bootsnap, but the message is only similar, not exact. The other page that came up was a SO question but it wasn't the point of the question so no one mentioned it.
[16:22:58] brandoncordell: Is there a way to run a stacktrace along with bin/update or similar commands?
[17:26:39] charlielor: I kept getting this error Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development on my page.
[17:28:22] charlielor: so I ran rails db:migrate RAILS_ENV=development and I got this error: https://kopy.io/uaulC
[17:57:30] blindMoe: Has anyone ran into an issue with send_early_hints from rspec tests when upgrade to rails 5.2? I can't seem to figure out what is happening since it says it is trying to call it on an OpenStruct yet the request object in the test is what is should be
[18:00:32] charlielor: What does this error Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for: means?
[19:30:12] MrPunkin: How can I convert crazy unicode text into normal text? I have a string that is all \u000e\u000i stuff that I just want to work the same as if I ‘puts’ that data and it is rendered.
[20:00:52] fourcolors: I have a question about rake task. When I run a very large rake task that could take a day or two, what is the best way to do that without taking down the server?
[20:05:40] cpinto: @fourcolors can't answer from a rails perspective, but from an ops perspective that's an affirmative. have you thought about the task's recovery as well? (ie. how to resume work if the task for some reason fails)
[20:12:28] MrPunkin: apeiros: It’s getting used in hash keys (CSV parsing) and then fails to properly map to my other UTF-8 keys.
[20:13:37] apeiros: encodings can't be automatically detected (guessed at best), so unless you tell ruby which encoding it is, it'll assume it's the default (which in turn is usually utf-8)
[20:13:39] MrPunkin: Right, I did that. String is coming in as “ASCII-8BIT”. I’m using “encode” method to convert from that to UTF-8 while replacing invalid and undefined characters with nothing.
[20:14:56] apeiros: wrong question. #encode is the right way to switch text from one encoding to another. but that's not what you need to do here.
[20:16:22] apeiros: in cases where you can, supply the encoding in your IO operation. in cases where you can't do that, force_encoding is used to tell ruby which encoding the string actually has.
[20:17:18] apeiros: encode -> map some bytes to some other bytes, so characters stay the same. force_encoding -> do not change any bytes, only set the .encoding flag so ruby knows which character certain bytes represent.
[20:18:13] MrPunkin: I need to get that over to a usable format with invalid characters removed. So everything I read online said to use encode to do that.
[20:18:54] MrPunkin: I’m not guessing on the encoding for input, it’s already there from the Rails email attachment parser.
[20:20:01] MrPunkin: I don’t know it better, I’m admitting I don’t understand something, but your condecending assumptions that I’m just missing a huge part make it hard to actually get the help I need.
[20:22:05] apeiros: you are missing a crucial part. your problem getting help is your attitude, not mine. good luck.
[20:22:31] MrPunkin: If you can explain to me which part I’m missing I’m more than willing and happy to learn
[20:23:18] MrPunkin: In fact I’d prefer it, I’ve been reading about text encodings since Ruby 1.8.7 and don’t feel any smarter than I did 10 years ago on this particular topic.
[20:45:42] MrPunkin: apeiros: here’s actual code… https://gist.github.com/mrpunkin/3268736422c139782df054f712d232bf
[20:55:35] MrPunkin: apeiros: with my end goal being this data becoming hash keys and data, what work do I need to do on the string so that querying the hash by a set of expected keys will work?
[20:56:22] apeiros: the things I already told you. tell ruby the correct encoding via force_encoding, then translate it from there to utf-8 via encode.
[20:59:00] apeiros: (note, it is of course possible to use utf-16le encoded strings as keys, Hash doesn't care)
[20:59:32] MrPunkin: if I use force_encoding(“ASCII-8BIT”) or force_encoding(“UTF-8”) on the initial string or the string just before making a hash from it there is no change to the end result. This is where I clearly have no knowledge of what / when I’m supposed to do
[20:59:57] MrPunkin: I’ve tried all four methods and none result in valid hash key lookups for the “Date” key
[21:01:45] apeiros: you're mistaken. ruby wasn't saying that. ruby only reflects what you tell it directly or indirectly.
[21:02:06] MrPunkin: Okay, I get that. I’m relying on the string variable returned from the core Mail stuff to read the attachment body.
[21:02:27] MrPunkin: So if I receive another file and I can’t trust the software that reads the file how do I know which encoding it is?
[21:02:30] apeiros: and guessing is indeed difficult and takes experience. from your example, the null-bytes in between gave it away.
[21:03:15] apeiros: you chose a bad offset, so it looked like big endian. in your gist, it's visible that it's little endian, though. and the byte order mark ("FF FE") is the strongest indicator for that
[21:03:34] apeiros: but again: guessing is hard and bad. make sure your source tells you the encoding.
[21:03:41] MrPunkin: apeiros: So to expand on what you are saying about guessing… would it be correct to say there isn’t really a way I can accept user-generated files and get proper text output from them consistently because I don’t actually have control of the file data.
[21:04:15] apeiros: correct. if you don't have explicit information, it's a guessing game which is at best unreliable.
[21:06:42] apeiros: blame all the suckers who failed to implement (or use) a proper metadata format :-/ it's indeed a bummer and reason for a lot of problems.
[21:07:25] mrbubbles: Does anyone know whether it's possible to use send_file in a rails controller to send an image blob to a JS front end?
[21:09:35] mrbubbles: Ah, I was trying to I was use send_file path, type: 'application/pdf', disposition: 'inline' to send a PDF but for some reason the PDFs always come out blank in the front end, so I assumed I was doing something wrong
[21:12:10] mrbubbles: In the front end I'm using axios to GET the end point (using a Accept: 'application/pdf' header) then constructing a new Blob([response.data]. Does that sound correct?
[21:15:08] apeiros: just test the same URL via browser (or curl, if you need specific headers to be set)
[21:18:42] MrPunkin: apeiros: Okay, since I have a known expected keyset for this hash would it make sense to query the resulting string for one of these header keys and upon each failed attempt try another encoding until the common ones are exhausted? Seems for my specific scenario that could get me working without having any real clue to what the attachments real encoding is.
[21:18:58] mrbubbles: Thanks apeiros. Okay so the URL is working fine, so I guess that the Rails half of things is working great (as usual). Must be the JS end that's screwing up (as usual!)