Paperclip: Integration with Mailboxer Gem

Paperclip: integration with mailboxer gem

Two solutions:

  • use the built-in attachment made with carrierwave (source)

  • monkey patch the Message model:

in an initializer do:

Message.class_eval do

#your paperclip code goes here

end

And don't forget migrations!

Adding belongs to relationship to Ruby Gem Mailboxer

Although rewriting a custom Conversation system will be the best long-term solution providing the customization requirement (Like linking with other models for instance), to save some time at the moment I have implement the link with a ConversationLink Model. I hope it would be useful for anyone in the future who are at my position.

Model: conversation_link.rb

class ConversationLink < ActiveRecord::Base
belongs_to :conversation
belongs_to :linkingObject, polymorphic: true
end

then in each models I target to link with the conversation, I just add:

has_many :conversation_link, as: :linkingObject

This will only allow you to get the related conversation from the linking object, but the coding for reverse linking can be done via functions defined in a Module.

This is not a perfect solution, but at least I do not need to monkey patch the gem...

Create link_to for downloading a File from Paperclip gem?

Suppose your model is Boxholder

If you have @boxholder instance variable in your controller like:

    @boxholder = Boxholder.find(params[:id])

Then the following line could be your solution:

    <%= link_to  @boxholder.box_file_name,@boxholder.box.url %>

Bundler loaded gem order

I had to add a Railtie to make this work. Paperclip was loading before my gem but wasn't include until much later...

Why is my app trying to load bourbon?

Bourbon is a dependency in Administrate. Looks like there is a recent, open issue around this: https://github.com/thoughtbot/administrate/pull/673.



Related Topics



Leave a reply



Submit