Jesper Christiansen

Joined

4,500 Experience
24 Lessons Completed
3 Questions Solved

Activity

Posted in How do I update a user to admin in production?

TL;DR; SO yeah, it depends! But don't feel bad about utilizing rails console in production - we all do that, and it's perfectly fine!

I'd say that 100% depend on the type of app you're building. Will it have 500 admins, or just 1 or 2? If it's a very low number, updated that through the rails console is 100% a fine way to approach this. If you have MANY users that need to be admin, you could consider building some UI around this. It also depends on what you mean by admin. Does an admin user have the privileges to delete other users or records associated to other users? If that's the case i'd probably stick to doing it through rails console - if you add UI to it, you open up an attack vector. If your admin account somehow gets compromised, the attacker could make themselves admin etc etc :)

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.