Project

modulate

0.0
No commit activity in last 3 years
No release in over 3 years
Easily add the ability to upload documents to any ActiveRecord model
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0.2
~> 2.2.0
>= 0
~> 0.9.12
~> 2.13.0

Runtime

 Project Readme

#Modulate

Build Status Code Climate

##Overview

Modulate builds off CarrierWave and CarrierWave-Riak to allow quick integration of document storage to Riak. The generator will do the bulk of the work for you including building view partials that you can quickly incorporate if you chose to do so.

##Usage

Copy the engine migrations to your project and run the migrations.

  rake modulate_engine:install:migrations

  rake db:migrate

Run the generator for each ActiveRecord model you wish to add modulate to.

  rails generate modulate Account

You may optionally install the Riak test server in your application by passing the option to do so. If you use this option, remember to configure the 'source' line in spec/support/test_server.yml with the local Riak installation path. This option will only work if Rspec is installed.

  rails generate modulate --test-server

The command above will add the 'modulate' method to your model. By default, it will create a has_many relationship to the Modulate::Documents class. If you would prefer to call the association by something other than modulate_documents then alter this line of code, supplying the name you wish to call the association.

  class Account < ActiveRecord::Base
    modulate name = :attachments 
  end

If you are using mass-assignment protection in your models, add the following.

  attr_accessible :modulate_documents_attributes, :modulate_uploads_attributes

Modify the CarrierWave initializer to meet your needs. The default assumes you are running a standard local Riak installation. For more information on how to configure Riak see carrierwave-riak.

Modulate has the ability to track the user who added the document to the system. By default this will not be tracked, however, if you have a method that returns the current user and wish to track who is uploading documents, configure modulate with that method.

  # config/initializers/modulate.rb

  Modulate.configure do |config|
    config.user_method = :some_user
  end

If you choose to track users then make sure your controller assigns the 'attached_by_id'.

  # app/controllers/accounts_controller.rb

  AccountsController < ApplicationController
    def update
      @account = Account.find(params[:id])
      @account.attributes = params[:account]

      @docs = @account.modulate_documents.select(&:new_record?) 
      unless @docs.blank?
        @docs.each do |doc|
        @doc.attached_by_id = current_user 
      end

      if @account.save
        flash.now[:notice] = "successfully"
        redirect_to accounts_path
      else
        flash.now[:alert] = "error"
        render :edit
      end
    end
  end