Jacob Warren
Joined
Activity
If you need Relay, I believe you have to pay for the pro version though.
Hey Roy!
Do you already have Shrine initialized and have an attacher created?
If you could show us how your model is set up, and whether or not you're doing this in a form or a service object, that would be helpful.
Essentially what you want to do is open and set the remote file to a variable name, something like "tempfile," and then call your model and set the attribute to the value of the tempfile. Then save the instance of the model.
So if you have a column called pdf_data, and that's where you want to store the file, and that colum belongs to a ticket table, then you would do:
tempfile = File.open('url_to_pdf')
@ticket.pdf = tempfile
@ticket.save
I would recommend opening PDF files and anything large to a background job though.
Posted in Optimizing Queries in Service Objects
Well hey right back at you Jacob!
Sorry for not explaining better. I'd like to refactor them to be more efficient to work with and speed them up as much as possible.
The calls will be used in multiple places. If a call is only going to be used in one place, I just place it in the model class.
I appreciate the input!
Posted in Optimizing Queries in Service Objects
I'm currently building an app and using namespaced service objects containing a single call method in each class.
Below is an actual method (I'm aware the ABC size is too large, I'm wanting to get it squared away before I break it apart into smaller chunks):
module Orders
class CalculateNextStep
include Services::Base
def call(order)
if order.next_step?
order.next_step = Course.where(id: order.course_id).first.course_steps
.where(position: 1).first.id
else
position = CourseStep.find(order.next_step).position
order.next_step = Course.where(id: order.course_id).first.course_steps
.where('course_steps.position > ?', position)
.first.id
end
end
end
end
My question is should I move the queries into a query object? And should I just use raw PG queries versus AR finder methods?