Jacob Warren


290 Experience
2 Lessons Completed
0 Questions Solved


Really, if you don't use Relay, you won't need the pro version. That's the only GraphQL gem I'm familiar with, though.
Of course it is. If that's what makes sense for your application. GraphQL APIs are far more flexible. Here's a great gem for building a GraphQL API in Ruby: https://github.com/rmosolgo/graphql-ruby.

If you need Relay, I believe you have to pay for the pro version though.

Posted in Uploading a file from remote url using shrine?

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

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
        position = CourseStep.find(order.next_step).position
        order.next_step = Course.where(id: order.course_id).first.course_steps
                                .where('course_steps.position > ?', position)

My question is should I move the queries into a query object? And should I just use raw PG queries versus AR finder methods?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.