Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I return an ActivateStorage blob URL in JSON

Peter vande Put asked in 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
Reply
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

Reply

I will also explain about Greatpeople me Kroger Schedule, Kroger great people.com schedule, feed kroger schedule today, krogerfeedback com schedule, Kroger employee schedule, Feed Kroger schedule.click here

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,140+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.