Giter Club home page Giter Club logo

carrierwave-tire's Introduction

Carrierwave::Tire

This gem provides CarrierWave functionality in Classes persisted by Tire

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-tire', git: "[email protected]:megorei/carrierwave-tire.git"

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-tire

Usage

Include CarrierWave::Tire mounter into your model and mount your uploader on a property. For more information about how to write an uploader see CarrierWave documentation.

class Article
  include Tire::Model::Persistence
  include CarrierWave::Tire

  property :filename

  mount_uploader :image, ImageUploader, mount_on: :filename
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

carrierwave-tire's People

Contributors

dinge avatar dpisarewski avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

princejoseph

carrierwave-tire's Issues

Getting this error on calling destroy on Tire Persistence model: NameError: undefined local variable or method `image' for

I am using Tire gem for persistence and I used this gem to bind with carrierwave. My model looks like this:

class Article
  include Tire::Model::Persistence
  include Tire::Model::Search
  include CarrierWave::Tire

  mount_uploader :avatar, AvatarUploader, mount_on: :avatar_filename
end

and my uploader looks like this:

class AvatarUploader < CarrierWave::Uploader::Base
  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

Now, create/update a record is working fine with uploads and all, but I am getting an error while deleting a file like this:

a = Article.find params[:id]
a.destroy

The error is here:

NameError: undefined local variable or method `image' for #<Article:0x9a28934>
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:407:in `method_missing'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/bundler/gems/carrierwave-tire-4604da35b759/lib/carrierwave/tire.rb:46:in `remove_avatar!'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:416:in `_run__127650161__destroy__1037496241__callbacks'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_destroy_callbacks'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/tire-0.5.7/lib/tire/model/persistence/storage.rb:61:in `destroy'
    from (irb):3
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /usr/local/rvm/gems/ruby-1.9.2-p320@os/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I am using commit 4604da3 code of the master branch of the gem.

My Gemfile

gem 'carrierwave-tire', git: "[email protected]:megorei/carrierwave-tire.git"

Gemfile.lock

GIT
  remote: [email protected]:megorei/carrierwave-tire.git
  revision: 4604da35b7596e2aebe1778c20fca9103043c74b
  specs:
    carrierwave-tire (0.0.1)
      carrierwave
      tire

The error references to this line of code in lib/carrierwave/tire.rb:46

 41         class_eval <<-RUBY, __FILE__, __LINE__+1
 42           def remove_#{column}!
 43             super
 44             _mounter(:#{column}).remove = true
 45             _mounter(:#{column}).write_identifier
 46             FileUtils.rm_rf File.dirname(image.file.path) if image.file.present?
 47           end

In line 46, it says undefined variable or method image. This error happens only in case of destroy.

I am using Tire gem version 0.5.7 and Carrierwave gem version 0.8.0

carrierwave (0.8.0)
tire (0.5.7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.