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