how to apply different watermark images based on different request host?

3 views
Skip to first unread message

gordon yeong

unread,
Jun 6, 2010, 1:03:34 AM6/6/10
to Paperclip Plugin
hi guys,

I successfully rolled out an app on say, www.a.com.
I use paperclip to upload and generate watermarks of images very
successfully.

Now, let's say I got another domain, www.b.com and I still want the
same application codes and db to be used.

I have successfully made the app show different logo based on the
request.host each time a request is being received.

I did however observe that my model does require me to specify the
logo file explicitly.

Given that the model can't have access to the request object , how do
I use different logo files (based on whether the request was from host
www.a.com or www.b.com )?

for example, if the request was made from www.a.com , then use the
file, "watermark-logo-a.png" for the uploaded images. Else if the
request was made from www.b.com, then use the file, "watermark-logo-
b.png".

Please help

thank you :)

gordon yeong

unread,
Jun 11, 2010, 3:02:27 AM6/11/10
to Paperclip Plugin

gordon yeong

unread,
Jun 13, 2010, 7:54:11 PM6/13/10
to Paperclip Plugin
Anybody?

Nicolas Block

unread,
Jun 14, 2010, 12:40:29 AM6/14/10
to papercli...@googlegroups.com
how about getting it from the save method in the controller?

On Jun 13, 2010, at 4:54 PM, gordon yeong wrote:

> Anybody?
>
> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Paperclip, Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Paperclip group:
> http://groups.google.com/group/paperclip-plugin
>
> To post to this group, send email to
> papercli...@googlegroups.com
>
> To unsubscribe from this group, send email to
> paperclip-plug...@googlegroups.com

Gordon Yeong

unread,
Jun 14, 2010, 12:45:38 AM6/14/10
to papercli...@googlegroups.com
yeap that's one way that is possible but i was wondering if anyone had any idea to do it on the model level (paperclip options)?

gordon yeong

unread,
Jun 15, 2010, 7:58:39 AM6/15/10
to Paperclip Plugin
hmmmm actually, it's easy to find out which host in the controller
(request object).

The question is, the model will not have access to the request
object. So how can we determine which graphic to use for queries to
different hosts?

William Ross

unread,
Jun 15, 2010, 11:14:55 AM6/15/10
to papercli...@googlegroups.com
On 15 Jun 2010, at 12:58, gordon yeong wrote:

> hmmmm actually, it's easy to find out which host in the controller
> (request object).
>
> The question is, the model will not have access to the request
> object. So how can we determine which graphic to use for queries to
> different hosts?

There are lots of ways to do this, but if you want to avoid defining a widely-accessible hostname variable you could add an asset_host_name column to the database table (changing 'asset' to the name of your attachment) and chain Attachment#assign so that it takes a hostname argument too:

def assign_with_host(uploaded_file, host="")
instance_write(:host_name, host)
assign_without_host(uploaded_file)
end
alias_method_chain :assign, :host

After that your Processor#initialize will able to call attachment.instance_read(:host_name), with the added benefit that if you ever regenerate the thumbnails the processor will still have access to the host_name value in the database.

best,

will

Reply all
Reply to author
Forward
0 new messages