Giter Club home page Giter Club logo

userstamp's Introduction

Userstamp Plugin (v 2.0)

Overview

The Userstamp Plugin extends ActiveRecord::Base to add automatic updating of 'creator', 'updater', and 'deleter' attributes. It is based loosely on the ActiveRecord::Timestamp module.

Two class methods (model_stamper and stampable) are implemented in this plugin. The model_stamper method is used in models that are responsible for creating, updating, or deleting other objects. The stampable method is used in models that are subject to being created, updated, or deleted by 'stampers'.

Installation

Installation of the plugin can be done using the built in Rails plugin script. Issue the following command from the root of your Rails application:

$ ./script/rails plugin install git://github.com/delynn/userstamp.git

or add it to your Gemfile:

gem 'userstamp'

and run bundle install to install the new dependency.

Once installed you will need to restart your application for the plugin to be loaded into the Rails environment.

Usage

In this new version of the Userstamp plug-in, the assumption is that you have two different categories of objects; those that manipulate, and those that are manipulated. For those objects that are being manipulated there's the Stampable module and for the manipulators there's the Stamper module. There's also the actual Userstamp module for your controllers that assists in setting up your environment on a per request basis.

To better understand how all this works, I think an example is in order. For this example we will assume that a weblog application is comprised of User and Post objects. The first thing we need to do is create the migrations for these objects, and the plug-in gives you a userstamps method for very easily doing this:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users, :force => true do |t|
      t.timestamps
      t.userstamps
      t.name
    end
  end
  
  def self.down
    drop_table :users
  end
end

class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts, :force => true do |t|
      t.timestamps
      t.userstamps
      t.title
    end
  end
  
  def self.down
    drop_table :posts
  end
end

Second, since Users are going to manipulate other objects in our project, we'll use the model_stamper method in our User class:

class User < ActiveRecord::Base
  model_stamper
end

Finally, we need to setup a controller to set the current user of the application. It's recommended that you do this in your ApplicationController:

class ApplicationController < ActionController::Base
  include Userstamp
end

If all you are interested in is making sure all tables that have the proper columns are stamped by the currently logged in user you can stop right here. More than likely you want all your associations setup on your stamped objects, and that's where the stampable class method comes in. So in our example we'll want to use this method in both our User and Post classes:

class User < ActiveRecord::Base
  model_stamper
  stampable
end

class Post < ActiveRecord::Base
  stampable
end

Okay, so what all have we done? The model_stamper class method injects two methods into the User class. They are #stamper= and #stamper and look like this:

def stamper=(object)
  object_stamper = if object.is_a?(ActiveRecord::Base)
    object.send("#{object.class.primary_key}".to_sym)
  else
    object
  end
  
  Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"] = object_stamper
end

def stamper
  Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"]
end

The big change with this new version is that we are now using Thread.current to save the current stamper so as to avoid conflict with concurrent requests.

The stampable method allows you to customize what columns will get stamped, and also creates the creator, updater, and deleter associations.

The Userstamp module that we included into our ApplicationController uses the setter method to set which user is currently making the request. By default the 'set_stampers' method works perfectly with the RestfulAuthentication plug-in:

def set_stampers
  User.stamper = self.current_user
end

If you aren't using ActsAsAuthenticated, then you need to create your own version of the set_stampers method in the controller where you've included the Userstamp module.

Now, let's get back to the Stampable module (since it really is the interesting one). The Stampable module sets up before_* filters that are responsible for setting those attributes at the appropriate times. It also creates the belongs_to relationships for you.

If you need to customize the columns that are stamped, the stampable method can be completely customized. Here's an quick example:

class Post < ActiveRecord::Base
  acts_as_stampable :stamper_class_name => :person,
                    :creator_attribute  => :create_user,
                    :updater_attribute  => :update_user,
                    :deleter_attribute  => :delete_user
end

If you are upgrading your application from the old version of Userstamp, there is a compatibility mode to have the plug-in use the old "_by" columns by default. To enable this mode, add the following line to the Rails.root/config/initializers/userstamp.rb file:

Ddb::Userstamp.compatibility_mode = true

If you are having a difficult time getting the Userstamp plug-in to work, I recommend you checkout the sample application that I created. You can find this application on GitHub

Uninstall

Uninstalling the plugin can be done using the built in Rails plugin script. Issue the following command from the root of your application:

script/plugin remove userstamp

Documentation

RDoc has been run on the plugin directory and is available in the doc directory.

Running Unit Tests

There are extensive unit tests in the "test" directory of the plugin. These test can be run individually by executing the following command from the userstamp directory:

ruby test/compatibility_stamping_test.rb
ruby test/stamping_test.rb
ruby test/userstamp_controller_test.rb

Bugs & Feedback

Bug reports and feedback are welcome via GitHub Issues. I also encouraged everyone to clone the git repository and make modifications--I'll be more than happy to merge any changes from other people's branches that would be beneficial to the whole project.

Credits and Special Thanks

The original idea for this plugin came from the Rails Wiki article entitled "Extending ActiveRecord" on the Rails Wiki (no longer published).

userstamp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

userstamp's Issues

Why does AR::Base get made stampable?

Is there any reason that self.stampable is in Stampable::included? Because ActiveRecord::Base includes Stampable, it means that not only do the callbacks get added twice (once via AR:Base, a second time when calling stampable in the model), but also every single model gets associations and callbacks set up for it.

I've removed it locally but am I going to break anything I'm not seeing by doing so?

issue after bundle install

I put the gem into my rails application, typed in bundle install, restarted server and the server crashed, displayed in console:
There was an error while trying to load the gem 'userstamp'. (Bundler::GemRequireError) Gem Load Error is: undefined method class_inheritable_accessor for ActiveRecord::Base:Class Did you mean? class_variables

Push latest version to rubygems

I tried using the version on rubygems and I was getting the error regarding "deprecation due to use of class_inheritable_accessor". Version 2.0.2 has that issue resolved.

Issue with dynamic_matchers after gem install.

so i added userstamp to Gemfile, run bundler and then when i try to
rails g migration somename
i get:
/home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/dynamic_matchers.rb:50:in method_missing': undefined methodclass_inheritable_accessor' for ActiveRecord::Base:Class (NoMethodError)
from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/userstamp-2.0.1/lib/stampable.rb:29:in block in included' from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/userstamp-2.0.1/lib/stampable.rb:25:inclass_eval'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/userstamp-2.0.1/lib/stampable.rb:25:in included' from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/userstamp-2.0.1/lib/stampable.rb:154:ininclude'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/userstamp-2.0.1/lib/stampable.rb:154:in <top (required)>' from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:inrequire'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in block in require' from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:inload_dependency'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require' from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/userstamp-2.0.1/lib/userstamp.rb:2:in<top (required)>'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in require' from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:inblock (2 levels) in require'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in each' from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:inblock in require'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in each' from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:inrequire'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler.rb:128:in require' from /home/sarin/projects/nau-pomocniczy/config/application.rb:13:in<top (required)>'
from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:24:in require' from /home/sarin/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:24:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in

'

using userstamps in existing schema

Hi,

Is it possible to use t.userstamps with change_table instead of create_table in migrations? I'd like to use this with an existing database and I can't get it to work that way, i keep getting this error:

undefined method `userstamps' for #ActiveRecord::ConnectionAdapters::Table:0x102e99f78

What am i doing wrong? How can i fix this?

thanks in advance,
_ miguel

Rails 4 not supported?

running tests now causes:

11:21:16 - INFO - Run all
11:21:16 - INFO - Running all specs
/home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `class_inheritable_accessor' for ActiveRecord::Base:Class (NoMethodError)
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/userstamp-2.0.1/lib/stampable.rb:29:in `block in included'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/userstamp-2.0.1/lib/stampable.rb:25:in `class_eval'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/userstamp-2.0.1/lib/stampable.rb:25:in `included'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/userstamp-2.0.1/lib/stampable.rb:154:in `include'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/userstamp-2.0.1/lib/stampable.rb:154:in `<top (required)>'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/userstamp-2.0.1/lib/userstamp.rb:2:in `<top (required)>'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /home/nir0/projects/vsluh4/config/application.rb:7:in `<top (required)>'
    from /home/nir0/projects/vsluh4/config/environment.rb:2:in `require'
    from /home/nir0/projects/vsluh4/config/environment.rb:2:in `<top (required)>'
    from /home/nir0/projects/vsluh4/spec/spec_helper.rb:3:in `require'
    from /home/nir0/projects/vsluh4/spec/spec_helper.rb:3:in `<top (required)>'
    from /home/nir0/projects/vsluh4/spec/models/post_spec.rb:1:in `require'
    from /home/nir0/projects/vsluh4/spec/models/post_spec.rb:1:in `<top (required)>'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:in `load'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:in `each'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:22:in `run'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:80:in `run'
    from /home/nir0/.rvm/gems/ruby-2.0.0-p195@vsluh4dev/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:17:in `block in autorun'

appears when model_stamper is added into user model

Best changes from forked repos

Hey,

Since this plugin seems to be getting some attention again, I would suggest pulling in the changes from this repo:

https://github.com/insphire/userstamp

Specifically, the issues that are addressed that haven't been updated in this repo yet:

  • deleter option defined as a preference instead of looking for acts_as_paranoid
  • creator/updater ids set before_validation instead of on save (so that presence can be verified in validations)
  • a few issues related to class names

I can put in a pull request if it would help

creator not set until after validation

Is there any reason why the stamper couldn't be set before validations?

I have a case where I want to ensure that a creator doesn't already have an object, but the creator id doesn't get set until after validations.

I changed stampable.rb to have
before_validation :set_updater_attribute
before_validation_on_create :set_creator_attribute

Is there a reason why this is a bad idea? (sorry if this covered in a google group already)

Userstamps not set when updating/creating children

Hello,

When one updates or creates children with complex forms using accept_nested_attributes_for, the userstamps don't get updated for the modified children.

I think instead of using a before and after filter in the Stampable module, you should use an alias_method_chain (e.g. base.alias_method_chain :create, :userstamps) as in Rails' Timestamp module.

This worked for me

Regards

before_filter to before_action for Rails 5

Please correct before_filter and after_filter on before_action and after_action for Rails 5

userstamp/lib/userstamp.rb

module Ddb
  module Controller
    ...
    module Userstamp
      def self.included(base) # :nodoc:
        base.send           :include, InstanceMethods
        base.before_filter  :set_stamper
        base.after_filter   :reset_stamper
      end
    end
   ...
  end
end

Rails 4.1 support: "creator" method name conflict

This is ugly, but "creator" association should probably be renamed to support Rails 4.1 and up.

I'm getting the following error right after Rails 4.1 upgrade:

/Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activerecord-4.1.0/lib/active_record/associations/builder/association.rb:30:in `build': You tried to define an association named creator on the model User, but this will conflict with a method creator already defined by Active Record. Please choose a different association name. (ArgumentError)
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activerecord-4.1.0/lib/active_record/associations.rb:1421:in `belongs_to'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/bundler/gems/userstamp-777633aa564f/lib/userstamp/stampable.rb:82:in `block in stampable'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/bundler/gems/userstamp-777633aa564f/lib/userstamp/stampable.rb:81:in `class_eval'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/bundler/gems/userstamp-777633aa564f/lib/userstamp/stampable.rb:81:in `stampable'
    from /Users/alexk/dev/alkaline-morning/app/models/user.rb:8:in `<class:User>'
    from /Users/alexk/dev/alkaline-morning/app/models/user.rb:1:in `<top (required)>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `load'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `block in load_file'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:633:in `new_constants_in'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:442:in `load_file'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:342:in `require_or_load'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:480:in `load_missing_constant'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:180:in `const_missing'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:238:in `const_get'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:238:in `block in constantize'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `each'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `inject'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `constantize'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:552:in `get'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:583:in `constantize'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise.rb:297:in `get'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/mapping.rb:77:in `to'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/mapping.rb:72:in `modules'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/mapping.rb:89:in `routes'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/mapping.rb:156:in `default_used_route'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/mapping.rb:66:in `initialize'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise.rb:331:in `new'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise.rb:331:in `add_mapping'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/rails/routes.rb:221:in `block in devise_for'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `each'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `devise_for'
    from /Users/alexk/dev/alkaline-morning/config/routes.rb:2:in `block in <top (required)>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:335:in `instance_exec'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:335:in `eval_block'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:313:in `draw'
    from /Users/alexk/dev/alkaline-morning/config/routes.rb:1:in `<top (required)>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/file_update_checker.rb:75:in `call'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/file_update_checker.rb:75:in `execute'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/initializable.rb:30:in `run'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /Users/alexk/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/application.rb:288:in `initialize!'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/railtie.rb:194:in `public_send'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/railtie.rb:194:in `method_missing'
    from /Users/alexk/dev/alkaline-morning/config/environment.rb:5:in `<top (required)>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
    from /Users/alexk/dev/alkaline-morning/config.ru:3:in `block in <main>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /Users/alexk/dev/alkaline-morning/config.ru:in `new'
    from /Users/alexk/dev/alkaline-morning/config.ru:in `<main>'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/server.rb:50:in `app'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/server.rb:130:in `log_to_stdout'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/server.rb:67:in `start'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:81:in `block in server'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/alexk/.rvm/gems/ruby-2.1.2@am/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

This would require a major version bump and a ton of pain for everybody who uses it. :(

rails 6

It seems as though the author isn't updating this project anymore

Is there anyone with an actively maintained fork?

Rails 3 compatibility

Probably not your top priority by any stretch of the imagination, but I'm currently getting this error under Rails 3.0.0-beta:

undefined local variable or method `stampable' for #Class:0x2793220 (NameError)

Thanks for the great library!

Migration helper not working with Rails 3.2.3

Migration helper 'userstamps' is not working in Rails 3.2.3, it seems that the t object in create_table and change_table in migration files pass object of ActiveRecord::ConnectionAdapters::TableDefinition type, But this was changed to ActiveRecord::ConnectionAdapters::Table in commit aee44af

userstamp and authlogic (and possible workarounds?)

I'm using Authlogic as it seems to be a popular and easy to implement authentication solution.

However, current_user is defined as a private method in the application_controller, or at least it's defined that way in the example and the Railscast.

Anyway, that seems to cause issues for userstamp. I suppose one way to fix this would be to make it a public method?

Also, another thing that seems to work is to do this:
def set_stamper
#User.stamper = self.current_user
User.stamper = current_user
end

in the userstamp.rb file.

Any thoughts on which solution is better or if there's another way superior to either of those?

Rails 4.2.5 - conflict with a method creator

Gemfile

gem 'rails', '~> 4.2', '>= 4.2.5'
gem 'userstamp', :git => 'https://github.com/stricte/userstamp.git', :branch => 'rails4'

User model

class User < ActiveRecord::Base
  ...
  model_stamper
  stampable
  ...
end

I have this message

You tried to define an association named creator on the model User, but this will conflict with a method creator already defined by Active Record. Please choose a different association name. (ArgumentError)

How I can fix it?

Warning of "class_inheritable_attribute is deprecated"

Hi,

I have upgraded rails 3.0 to rails 3.1.
When I use userstamp (gem "userstamp", "~> 2.0.1"), when use rails console, rails server, rake, etc, the deprecated warning emerged:


DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from  at /home/simon/rorworkspace/rails310/railsdemo/config/application.rb:13)

When I discarded userstamp gem in Gemfile, the warning disappeared.

Everything works OK with the warning message, but it confuse me every time.

Is any new version have fixed this warning?

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.