Haroon Ahmed

Respect my limits

15 Mar 2017

In rubocop I have set my number of characters per line to 100. Sooner or later something happens where limits are tested, trying to find ways to work around this is very interesting.

I was using the paperclip gem to allow uploads for word documents only. The :content_type had an array of valid types which were overflowing the 100 char limit, whilst going through the documentation on GitHub it took me a while to realise I can just create an array and hand it over to the ``:content_type` sweet!

Here is what I settled on:

class Template < ApplicationRecord
 has_attached_file :document
 valid_types = [
validates_attachment_content_type :document,
                                  :message => only microsoft word documents allowed,
                                  :content_type => valid_types