Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including a Module before validations cancels validations #1388

Closed
victorbstan opened this issue May 28, 2011 · 2 comments
Closed

Including a Module before validations cancels validations #1388

victorbstan opened this issue May 28, 2011 · 2 comments

Comments

@victorbstan
Copy link

I have found that if I include a simple module from the lib folder in a Model, it cancels all validations if i include it at the top of the file. I have to include it bellow all validations to make it not cancel validations.

Also, I can't call the code in the Module although it is 'detected' and no error of missing method is thrown...

I have also tested with just including an empty module in a model and this also cancels all validations.

class Collection < ActiveRecord::Base
require MyAutoSort

Is this normal?

GEMFILE:

source 'http://rubygems.org'

gem 'rails', '~> 3.0.7'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'aws-s3', :require => 'aws/s3'
gem 'haml'
gem 'sass'
gem 'devise'
gem 'hpricot'
gem 'ruby_parser'
gem 'sitemap_generator'
gem 'haml-rails'
gem 'formtastic', '~> 1.1.0'
gem 'simple_form'
#gem 'carrierwave'
gem 'paperclip', "~> 2.3"
gem 'mini_magick'
gem 'spectator-validates_email', :require => 'validates_email'
gem 'jquery-rails'
gem "geocoder", :require => "geocoder"
gem 'will_paginate', '~> 3.0.beta'
gem 'humanizer', '~> 2.4'
gem 'aws-s3'

group :development do
  gem 'sqlite3-ruby', :require => 'sqlite3'
  gem 'nifty-generators'
end

group :production do
  gem 'mysql2'
  gem 'ruby-mysql', '~> 2.9.3'
  gem 'exception_notification_rails3', :require => 'exception_notifier'
end

group :test do
  gem 'rspec'
  gem 'rspec-rails'
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'webrat'
  gem 'pickle'
  gem 'jasmine'
  gem 'factory_girl'
  gem 'builder', '~> 2.1.2'
  gem 'launchy'
  gem "mocha"
end
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end
@pixeltrix
Copy link
Contributor

I'm not sure why you're not getting error messages but your code is wrong - it should be:

require 'my_auto_sort'

class Collection < ActiveRecord::Base
  include MyAutoSort
  # Rest of model code
end

In future can you please use the [Ruby on Rails: Talk][1] mailing list for support

@victorbstan
Copy link
Author

Ah, I see what you did there, I'll try that out... thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants