Skip to main content
The 2024 Developer Survey results are live! See the results

All 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 ...
Dan's user avatar
  • 1,278
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. # == ...
VegaStudios's user avatar
1 vote
1 answer
54 views

How to execute code "before_serialize"? or How can I sanitize attributes before they are serialized?

I am following this pattern to ensure all my attributes are normalized before they are saved: class MyModel < ApplicationRecord before_validation :normalize_attributes def normalize_attributes ...
fguillen's user avatar
  • 38.1k
0 votes
1 answer
307 views

Rails/MySQL: better to use JSON column or serialized text for non-JSON use?

With my Rails 7.1.3 app, I have have a MySQL 8 db with a table users. Each user has many translations, and the translations belong to another table languages. I'd like to cache the results of a query ...
nimmolo's user avatar
  • 521
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 ...
bcan001's user avatar
  • 147
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 ...
Tsubasa's user avatar
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 ...
Steven's user avatar
  • 13
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 ...
Launemax's user avatar
  • 135
0 votes
1 answer
82 views

ROR: Serializing output for multiple objects

I am learning rails, and using active_model_serializers gem. I need to get the customized output in JSON from two different tables. Here is an example car: id, name, color, size, shape, date... ...
SS Sid's user avatar
  • 459
1 vote
1 answer
511 views

Trying to implement Rails ActiveJob Serializer

I am trying to implement an ActiveJob Serializer in Rails 6.1.7 so that I can deliver email with the deliver_later method. Examples I see of this say that I should extend the class ActiveJob::...
Edward Caulfield's user avatar
0 votes
0 answers
69 views

How do I render a nested model with a belongs_to association as an array in my API? I'm getting this: Error: Objects are not valid as a React child

I am trying to nest my models this way: a User has many Events, and an Event belongs to a client. I was able to get this working, my API is looking like this right now. { "id":1, "...
angiem103's user avatar
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 :...
Heartcroft's user avatar
  • 1,692
0 votes
0 answers
86 views

JSON response with nested calculated key in ROR

I have a model and I need to group some of relations and make json response. For example i have Models: users: { orders ... } orders: { order_group items ... } items: { ... } order_groups:...
exvayn's user avatar
  • 278
0 votes
0 answers
128 views

Advice for caching nested related records

I have relations like this: class Post < AbstractModel belongs_to: :user has_many :comments has_many :votes class Comment < AbstractModel belongs_to :post belongs_to :user has_many :...
nimmolo's user avatar
  • 521
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) ...
iftheshoefritz's user avatar

15 30 50 per page
1
2 3 4 5
35