New Discussion

Notifications

You’re not receiving notifications from this thread.

How do I return an ActivateStorage blob URL in JSON

2
Rails

In our system we are sending webhook to an endpoint with serialized JSON for the object JobApplication.
The JobApplication has a resume attached using ActiveStorage. ( has_one_attached :resume)
How can I return a public URL to the resume in my JSON

class JobApplicationSerializer
  def self.exploded_json(object)
    json =object.to_json(:except => [:user_id,:created_at, :updated_at],
                         :include => [
                           :state => {:only => [:id, :name,:code]},
                           :country => {:only => [:id, :name,:code]}
                         ]
    )
    return json
  end

end
include Rails.application.routes.url_helpers

  def self.exploded_json(object)
    json =object.to_json(:except => [:user_id,:created_at, :updated_at],
                         :include => [
                           :state => {:only => [:id, :name,:code]},
                           :country => {:only => [:id, :name,:code]}
                         ]
    )
    if object.resume.attached?
      json[:resume] = {
        url: rails_blob_url(object.resume)
      }
    end
    return json
  end

Join the discussion
Create an account Log in