All Questions
Tagged with ruby serialization
295
questions
0
votes
0
answers
26
views
JBuilder and Rails 6.1
I am working on a POC for switching from active-model-serializer to jbuilder. I am very sad to see AMS being relegated to unsupported status. It's going to take forever to convert our 200+ serializers ...
0
votes
1
answer
53
views
Updating a serialized field in Rails
I have a serialized attribute in my Rails model and am attempting to update it. The Block#preferences attribute was first generated through a migration as a text type. We use Postgresql 14.
# == ...
0
votes
1
answer
48
views
Ruby Serialising and deserialising json
I have this two function to serialise and deserialise game state. I got it working okay. But It feels very cluttered and messy. Is there a better approach of doing this?
There is two different class ...
0
votes
1
answer
105
views
How to serialize a postgres column in ruby on rails correctly
I'm trying to save to a column which has a datatype of 'string', within a postgres db using ruby on rails. Say I want to save an integer to this column. Is there any way to serialize the saved data in ...
2
votes
1
answer
2k
views
ActiveRecord serialize coder argument not seeming to work
I have an Entry class that has a Charge attribute that I want to instantiate from a string as a Charge object when read from the DB:
class Entry < ActiveRecord::Base
serialize :charge, Charge
end
...
0
votes
1
answer
55
views
Cannot use the helper method `current_user` in devise
I am building a simple todo app with nextjs and rails.
I am using devise for user authentication, but I can't use current_user.
Specifically, I am using JSON API Serializer to return user information ...
0
votes
1
answer
111
views
Ruby: How to pass parameters to oj_serializers
I'm using Oj Serializer: https://github.com/ElMassimo/oj_serializers.
I want to know how can I pass some variable(eg. CurrentCurrent) from controller to Serializer?
This for example controller:
class ...
0
votes
1
answer
149
views
Convert a returning Hash of a Model's method to a serializable_hash (for as_json)
My Modelclass has a method, that returns some calculated data in form of a Hash. In the Controller I want to use this data, but want to include only some parts of the Hash.
My first idea was, to use ...
2
votes
2
answers
135
views
Is it a good idea to serialize immutable data from an association?
Let's say we have a collection of products, each with their own specifics e.g. price.
We want to issue invoices that contain said products. Using a direct association from Invoice to Product via :...
0
votes
2
answers
73
views
ApplicationRecord#save! does not work on models created with Marshal.load
I wanted to copy some data from one Rails server (same application, different DB) to another... for various reasons I chose to experiment with a hacky method in the console: Marshal.dump(MyModel.all) ...
0
votes
1
answer
40
views
Serialization of Class-Based Object Under Rails Model
Consider the concept of a "score translator": given a (numerical) score in a test, the translator takes the score as an input and returns a verbal evaluation. An example for such translation ...
0
votes
1
answer
402
views
Serialize/ Deserialize arbitrary Ruby objects to database
I have a use case to store arbitrary objects (classA or classB or classC) in a column of a database table. Then when I read it, I would like to deserialize it back to the original class (A or B or C) ...
0
votes
1
answer
1k
views
Mapping large array of objects with the spread operator
I've got a API-only Rails 7 app with Ruby 3.1.2. I'm using the jb gem for serialization of data.
In the app, I have a Part table, which belongs_to a Company. I want to deliver the name of the company ...
0
votes
1
answer
103
views
Ruby creating file in home directory instead of current one
I'm running my program in a directory with the following path:
/home/user/Desktop/Ruby/Projects/event_manager/lib,
trying to accomplish the following:
Dir.mkdir('output') unless Dir.exist?('output')
...
2
votes
1
answer
591
views
Ruby YAML serialization and unserialization
I have a problem with Object-Oriented Project Hangman - serialization part. I saved my code in serialize method, but when I try to unserialize it, I have a problem with it. I see all components of ...