All threads / How do I return an ActivateStorage blob URL in JSON

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
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

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

Join the discussion

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

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

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

    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

    © 2021 GoRails, LLC. All rights reserved.