#RubyOnRails - 12 April 2019
« Back 1 day Forward 1 day »
[05:16:08] Fira: I'm trying to find a boilerplate for running stateful background workers on Rails... Basically attempting to run Web Scrapping jobs with Sessions handling. No matter how I search, everything point me to independant stateless job systems, ActiveJob/resque/sidekiq. Not sure what to do... Should I just roll a separate Rails app for that ?
[11:33:28] jarr0dsz: hello everyone! Im having a problem im breaking my head on hope some experts can point me in the right direction.
[11:34:10] jarr0dsz: i know its not fancy i have database serialized column. which needs to be exported to CSV so i can reimport it in another database.
[11:41:49] tbuehlmann: jarr0dsz: active record will deserialize it when you fetch it. when creating the csv, you could use the same serialization mechanism
[11:42:29] jarr0dsz: tbuehlmann i tried column_serialized.to_csv when saving the row for the csv but that fails
[11:44:01] jarr0dsz: so in database #1 its stored correctly, then i move it to csv and import in database #2
[11:44:20] jarr0dsz: if i compare the columns in both databases they are not the same, thus the export of the serialized column to csv is incorrect
[11:44:51] jarr0dsz: but im really struggling how to resolve it, tried serveral solutions from stackoverflow, the docs i just don't understand how i should approach this
[11:46:11] tbuehlmann: `serialize` probably serializes to yaml, so you could manually serialize the object to yaml
[11:48:03] jarr0dsz: so you suggest i serialize the column to yaml? so the csv value contains the yaml object?
[11:48:21] jarr0dsz: my code example is a bit modified i see i make some mistake but you get the idea
[11:51:08] tbuehlmann: is the receiving side also serializing that column? because it basically doesn't matter to what format you serialize in the csv as you have to deserialize on the receiving end either way
[11:58:17] jarr0dsz: i dont like serialized column but its for a simple selection list. so what i basically do is re-build the object from the csv values
[11:58:53] jarr0dsz: so it look like that does the trick, which i very much thank you sir. I tried for 1 hour to resolve this to no avail
[11:59:19] jarr0dsz: should have realized, its saved as some sort of object ( yaml) then export to that object format
[11:59:55] jarr0dsz: how would i then import the database on the other end? I cannot do User = User.new, User.column_serialized = csv_file.serialized_column like that
[12:03:16] jarr0dsz: another thing im really struggling with and tried several attempts is to convert this serialized object to a comma seperated list
[12:04:20] jarr0dsz: i tried several .map and object methods but havent really got it worked out either do you know how i could make the yaml object into something like 1,2,3 when for example the object itselfs contains 1,2,3 values as yaml object?
[12:06:12] tbuehlmann: you wouldn't work with the object's yaml representation directly, you would work with the object. what exactly is it? an array? of strings?
[12:08:18] jarr0dsz: in my serialized column it is stored like https://wtools.io/paste-code/bhM integers stored as string because column is varchar
[12:10:30] tbuehlmann: no, yaml would correctly store them as integers. if they are strings, they were likely strings from the very beginning
[12:11:52] jarr0dsz: ah that is a stupid question, the yaml object would determine what type it is stored right
[12:12:17] jarr0dsz: would that mean that quotes " around the object mean they are string and non quotes they are integers?
[12:14:38] jarr0dsz: its not fancy i can look lateron to refactor that, but for now what would be the best way i convert them to 1,2,3 format?
[12:15:09] jarr0dsz: i now have a very ugly do loop on the object to build this string but its not fancy ( because i could not find a solution to do it neatly 0
[12:16:12] tbuehlmann: if the question is how to convert an array of strings to an array of integers, one simple one would be ['42'].map(&:to_i)
[12:40:28] jarr0dsz: tbuehlmann i need it to not be an array but a comma seperated list btw so from "1","2","3', to 1,2,3
[13:16:42] kidPalooma: Hello, I have these 3 namespaced classes: https://gist.github.com/salami-art/95f208eb602629cc3b2112f940ed3ebd . When I update a Rating::Type its nested options already have a rating_type_id and it saves correctly, however, when I try to create a new Rating::Type it gives an error because it fails to associate the new record
[13:17:35] kidPalooma: more clearly: the Rating::Options sent with the Rating::Type's nested attributes are created without a rating_type_id
[13:18:10] kidPalooma: I suspect that the problem is originated by the classes being namespaced but I thought that adding the foreign_key parameter would solve the issue
[13:35:24] jtperreault: terens: https://guides.rubyonrails.org/active_record_querying.html#joining-tables
[14:46:23] ss942: What version of deface gem should I use after vulnerability was found in nokogiri?
[17:34:04] cek: Something's up with turbolinks:load handler, it doesn't get triggered when navigating to a page that includes a JS that hooks on it
[19:09:04] cek: I'm hooking up on` turbolinks:load` in a JS script sourced in a layout loaded via turbolinks
[21:13:21] wallace_mu: Happy Friday all, may i ask a question about a error: nnectionNotEstablished: ActiveRecord::ConnectionNotEstablished, the reason i guess this because i put this in application.rb file ` ActiveRecord::Base.connection.table_exists?('table_name')`, i need to initialize some variable if the table exists, anyone know why it happens? is there the wrong i should check db connection.