Thank you! Your feedback has been delivered
Thank you! Your feedback has been sent

Set up a Discourse avatar plugin

I am an ASP.NET dev that knows nothing of ruby. I've set up discourse-docker following these instructions:

https://meta.discourse.org/t/beginners-guide-to-deploy-discourse-on-digital-ocean-using-docker/12156/69

Here is some help I got from the Discourse forum regarding what I need:

https://meta.discourse.org/t/adding-own-avatar-provider/14947/6

Here they are explaining the proper way to install plugins

https://meta.discourse.org/t/first-time-trying-to-install-a-plugin-getting-fatal-peer-authentication-failed-for-user-discourse/14977

So I have a REST service that returns the avatars for me based on username: http://avatarservice.com/Username.png. What I need is a discourse plugin that will override the gravatar urls with this one. It should be a simple matter if you are experienced with ruby.

The deliverable should be the plugin, and instructions of how to install it. So I would ssh into my box, ssh into the docker container with ./launcher ssh app, then i would follow your instructions.

User Gravatar

Phaed

Posted Apr 23 2014 12:59 UTC

$30


  • Assigned To guyisra
  • Solved
  • ruby
    Docker
    Discourse
  • 946 Views

6 Replies


seems that you got the answer in there with

after_initialize do
  User.class_eval do
    def avatar_template
      # Generate your URL here, with "{size}" where the image size should be substituted.
    end
  end
end

this basically adds(or overrides) the avatar_template method in runtime so you can add your own implementation

in your case I guess it would be

def avatar_template
  "http://avatarservice.com/#{self.username}.png"
end

since you said you don't know ruby - every method returns what is last, so in this case it returns the string, and with " " it can do interpolations, meaning placing variables inside the string via #{ }. In this case, I am assuming there is a username attribute for the User model and I access it with self.username (since its a class method)

so in overall, that would be

after_initialize do
      User.class_eval do
        def avatar_template
      "http://avatarservice.com/#{self.username}.png"
    end
   end
 end
User Gravatar

guyisra

Posted Apr 23 2014 13:08 UTC

Solution

This didn't solve your task? Get your own custom solution.

That would be the trivial part indeed. My main problem is in how to install it and have it show in production. They try to explain here and I can make those edits to that file but then what. I need instructions on how to install this properly so that i can re-bootstrap the container and have it get automatically installed.

They were giving me answers but with my lack of knowledge on everything related (ruby, rails, docker) which their answers take for granted I see myself asking these guys 50 questions before I get this set up.

User Gravatar

Phaed

Posted Apr 23 2014 13:12 UTC

Is your problem how to install discourse or how change the avatar source?

The code above runs when the entire code base runs. There isn't really a plug in to install since is just a method overloading...

If you put the code above, what is the result in production?

User Gravatar

guyisra

Posted Apr 23 2014 13:31 UTC

Ok gonna try sec.

User Gravatar

Phaed

Posted Apr 23 2014 13:35 UTC

No I haven't been able to get it working. My problem is not with the plugin itself which is one line basically. Its how to get it set up.

User Gravatar

Phaed

Posted Apr 23 2014 15:22 UTC

Got it to work. You saved me on the ruby part so ill give you the answer.

User Gravatar

Phaed

Posted Apr 23 2014 15:33 UTC

Add a reply

By posting a reply on CodersClan you agree to our Terms & Conditions