Как загрузить изображения, документы Word и / или PDF-файлы с помощью направляющих Paperclip 4

Я хотел бы разрешить пользователям загружатьWord Docs а такжеPDF файлы к моему приложению рельсов. Мое приложение похоже на приложение Pinterest, пользователи могут создаватьPins где они прикрепляют картинку с последующим описанием (используетсяСкрепка для бумаг прикрепить изображение кШтырь).

Вот мойPins модель:

class Pin < ActiveRecord::Base
    belongs_to :user
    has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    validates_attachment :image, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
    validates :image, presence: true

    end

мойPins контроллер:

class PinsController < ApplicationController
  before_action :set_pin, only: [:show, :edit, :update, :destroy]
  before_action :correct_user, only: [:edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]

  def index
    @pins = Pin.all.order("created_at DESC").paginate(:page => params[:page], :per_page => 15)
  end

  def show
  end

  def new
    @pin = current_user.pins.build
  end

  def edit
  end

 def create
    @pin = current_user.pins.build(pin_params)
    if @pin.save
      redirect_to @pin, notice: 'Pin was successfully created.'
    else
      render action: 'new'
    end
  end

  def update
    if @pin.update(pin_params)
      redirect_to @pin, notice: 'Pin was successfully updated.'
    else
      render action: 'edit'
    end
  end

  def destroy
    @pin.destroy
    redirect_to pins_url
  end

  private

    def set_pin
      @pin = Pin.find(params[:id])
    end

    def correct_user
      @pin = current_user.pins.find_by(id: params[:id] )
      redirect_to pins_path, notice: "Not authorized to edit this Pin" if @pin.nil?
    end


    def pin_params
      params.require(:pin).permit(:description, :image)
    end
end

Интересно, нужно ли мне просто создать еще одинhas_attached_file метод дляWord документы а такжеPDF-файлы файлы в моемШтырь модель, а затем создать представление для пользователей, чтобы загрузить файл.

Ответы на вопрос(1)

Ваш ответ на вопрос