Jesper Christiansen

Joined

3,800 Experience
24 Lessons Completed
2 Questions Solved

Activity

Posted in Manipulate photos already on S3 or Spaces

Hi Ryan,

There's a few different approaches to this.

I'd either set up a after_create callback in your model, which would enqueue your resizer job.

class Photo < ApplicationRecord
  after_create :enqueue_resizer_job

    private
    def enqueue_resizer_job
      PhotoResizerJob.perform_later(id)
    end
end

Your job would then get the image uploaded to S3, resizing it, and rewriting it to S3. You could then set an attribute on your Photo model to true (resized = true) for instance.

Another way, could be to do this in a batch daily, hourly or whatever. For that I'd recommend the whenever gem (https://github.com/javan/whenever). That way you could do something like

Photo.where(resized: false).each do |photo|
  # resize photo and set resized to true
end

Posted in Can some explain this line of code

Hi,

params is a json-blob that "basically" comes from the users browser. So for a HTTP GET request, if someone visits a URL like: /users?something=test&name=john - then params will look like:

{
something: "test",
name: "john"
}

The same basically goes for a HTTP POST request.

So params["payload"] in your example, references the content within:
"payload": {
"useriden": "900af657a65e",
"score": 50,
"Average": 25
},

so { useriden: "900af657a65e", score: 50, average: 25 }

I hope that makes sense? It's essentially data that hits the ruby backend via a HTTP request.