I am using:
Rail 4.1.7
Ruby 2.1.4
I just installed Audited GEM:
gem "audited-activerecord", "~> 4.0"
$ rails generate audited:upgrade
$ rake db:migrate
Model
class Opportunity < ActiveRecord::Base
...
audited
...
end
And when I run:
Opportunity.audits.count
I get this error:
2.1.4 :001 > Opportunity.audits.count
NoMethodError: undefined method `audits' for #<Class:0x007ff7946656f0>
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.7/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from (irb):1
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/commands/console.rb:90:in `start'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/commands/console.rb:9:in `start'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/railties-4.1.7/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
from /Users/andreucasadella/rails_projects/crm/bin/rails:8:in `<top (required)>'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:241:in `load'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application.rb:183:in `block in serve'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application.rb:156:in `fork'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application.rb:156:in `serve'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application.rb:131:in `block in run'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application.rb:125:in `loop'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application.rb:125:in `run'
from /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/spring-1.2.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'2.1.4
I am using Ruby 2.1.4 and there is a warning sign "Audited may work just fine with a Ruby version not listed above (Latested 2.1.2), but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a pull request."
Has anyone experienced this before?
The audits method is an instance method, i.e. it is for one opportunity, not the entire Opportunity class.
Your code:
Opportunity.audits.count # Fails because audits is not a class method.
Solution code:
opportunity = Opportunity.first # any search you want
opportunity.audits.count # Succeeds because audits is an instance method.
Related
I am new to the ruby environment. I configured ruby and when I start the server I am hit with the series of errors. Can someone please give me a hand please.
2.3.1 :001 > rails s
NameError: undefined local variable or method `s' for main:Object
from (irb):1
from /Users/User/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/workspace/dineconnect-backend/bin/rails:9:in `<top (required)>'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:191:in `block in serve'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161:in `fork'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161:in `serve'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:131:in `block in run'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125:in `loop'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125:in `run'
from /Users/User/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/User/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/User/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
You are trying to start rails server in interactive Ruby Shell (IRB or irb), or may be rails console.
use the command
rails s
in your terminal
You should have to look into this http://guides.rubyonrails.org/getting_started.html for the rails basics.
You are using rails console. Get out of the console by typing quit and then type rails s
I'm using Ruby 1.9.3 and Rails 3.2.17 for this project. I plan to upgrade to Rails 4 but meet a lot gem incompatibilities, so I try to update some gem at first.
I am updating formtastic from 2.0.2 to 3.1.3.
I see a lot of deprecation warnings like this:
DEPRECATION WARNING: input_class is deprecated and will be removed from Formtastic 4.0 (configure Formtastic::FormBuilder.input_class_finder instead (upgrade guide on wiki: http://bit.ly/1F9QtKc )). (called from _app_views_prescriptions__fields_html_haml___278490936240938991_103076320 at /home/hegwin/Workspace/rails_projects/pharmmd/app/views/prescriptions/_fields.html.haml:7)
And I followed formtastic wiki Upgrading to Formtastic 3.1 , and I added these two lines to config/initializers/formtastic.rb
Formtastic::FormBuilder.action_class_finder = Formtastic::ActionClassFinder
Formtastic::FormBuilder.input_class_finder = Formtastic::InputClassFinder
After that when I tried to run the rspec, it threw an error:
NoMethodError: undefined method `eager_load' for #<Rails::Application::Configuration:0x00000006306a50>
/home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `eager_load' for #<Rails::Application::Configuration:0x00000006459b50> (NoMethodError)
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:32:in `use_const_defined?'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:69:in `<class:NamespacedClassFinder>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:24:in `<module:Formtastic>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:1:in `<top (required)>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/formtastic-3.1.3/lib/formtastic/action_class_finder.rb:7:in `<module:Formtastic>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/formtastic-3.1.3/lib/formtastic/action_class_finder.rb:1:in `<top (required)>'
from /home/hegwin/Workspace/rails_projects/pharmmd/config/initializers/formtastic.rb:104:in `<top (required)>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:50:in `load'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:50:in `load'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:43:in `load'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `block in load'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `load'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/engine.rb:593:in `block (2 levels) in <class:Engine>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/engine.rb:592:in `each'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/engine.rb:592:in `block in <class:Engine>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `instance_exec'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `run'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `each'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `run_initializers'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/application.rb:136:in `initialize!'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/hegwin/Workspace/rails_projects/pharmmd/config/environment.rb:5:in `<top (required)>'
from /home/hegwin/Workspace/rails_projects/pharmmd/spec/spec_helper.rb:12:in `require'
from /home/hegwin/Workspace/rails_projects/pharmmd/spec/spec_helper.rb:12:in `<top (required)>'
from /home/hegwin/Workspace/rails_projects/pharmmd/spec/features/patient_edit_medication.feature:1:in `require'
from /home/hegwin/Workspace/rails_projects/pharmmd/spec/features/patient_edit_medication.feature:1:in `<top (required)>'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /home/hegwin/.rvm/gems/ruby-1.9.3-p362#medpro/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
The issue is known to the formtastic team. See issues #1137 and #1135 for details. In short, a stop-gap measure is to utilize the issue_1135 branch of the sepastian fork. Here's the Gemfile line:
gem 'formtastic', :git => 'git://github.com/sepastian/formtastic.git', :branch => 'issue_1135'
A better idea is to fork that branch to create your own repository.
I am using the ancestry gem and i m testing my model in the console first.When i use
root = Message.create(:content => "hello")
It inserts data into the database but when i use
child = root.children.create(:content => "hhjjh")
It gives an error.This is the log
NoMethodError: undefined method `scoped' for #<Class:0x007fa4a61182b0>
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/ancestry-1.2.3/lib/ancestry/instance_methods.rb:136:in `children'
from (irb):2
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/console.rb:90:in `start'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/console.rb:9:in `start'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /Users/zeeshandar/chat/bin/rails:8:in `<top (required)>'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:183:in `block in serve'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:156:in `fork'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:156:in `serve'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:131:in `block in run'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:125:in `loop'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:125:in `run'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/zeeshandar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/zeeshandar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I don't know what i m doing wrong but i think this is suppose to work.Any ideas?
It looks like your version of Ancestry is 1.2.3 or something. Updating to a new version looks like it should fix that problem.
Gemfile
gem 'ancestry', '~> 2.1'
I wanna use sorcery gem using user authentication and mongid gem
add Gemfile to
gem 'sorcery'
$ bundle
$ rails g sorcery:install core reset_password
I was success using activerecord...
but mongoid not make defualt sorcery initial files..
why not make initial files
help expert persons :(
This is deprecated, in future versions you may need to `bundle binstub rails` to work around a system/bundle conflict.
/Users/user_name/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.0/lib/active_support/concern.rb:126:in `included': Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks)
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/sorcery-0.8.5/lib/sorcery.rb:73:in `block in <module:Sorcery>'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/sorcery-0.8.5/lib/sorcery.rb:72:in `module_eval'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/sorcery-0.8.5/lib/sorcery.rb:72:in `<module:Sorcery>'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/sorcery-0.8.5/lib/sorcery.rb:1:in `<top (required)>'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
from /Users/user_name/Desktop/rails/project/config/application.rb:14:in `<top (required)>'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application.rb:82:in `require'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application.rb:82:in `preload'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /Users/user_name/.rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/user_name/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/user_name/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I created a simple web project in ROR - postgresql as a DB
C:\Sites\nested>ruby -v
ruby 1.9.3p484 (2013-11-22) [i386-mingw32]
C:\Sites\nested>rails -v
Rails 4.0.2
When I try to add an automatic foreign key either by command line
C:\Sites\nested>gem install automatic_foreign_key
or edit the gem file by adding
# create automatic foreign key
gem "automatic_foreign_key", "~> 1.3.0"
I got the following error when running the server
C:\Sites\nested>rails s
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `to_sql' for class `ActiveRecord::ConnectionAdapters::Tab leDefinition' (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb:9:in `block in included'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb:6:in `class_eval'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb:6:in `included'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core.rb:32:in `include'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core.rb:32:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:229:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:229:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/automatic_foreign_key-.3.0/lib/automatic_foreign_key.rb:5:in `rescue in <top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/automatic_foreign_key-.3.0/lib/automatic_foreign_key.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:72:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:70:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:70:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:59:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:59:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler.rb:132:in require'
from C:/Sites/nested/config/application.rb:7:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:74:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:74:in `block in <top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:71:in `tap'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
FYI this is your error:
`alias_method': undefined method `to_sql' for class `ActiveRecord::ConnectionAdapters::Tab leDefinition' (NameError)
Looks like the gem is creating an alias_method for .to_sql. Alias method basicaly calls a method by another name, so you can use it in different contexts
We use alias_method :name, :title a lot, because we standardize our validations, meaning we need to keep the same method names each time
Error
The actual error is caused by your class not having the to_sql method. I've never encountered this, so I looked it up:
Seems the issue is caued by Rails 4. As for a solution, I would suggest that since automatic_foreign_key hasn't been updated since 2011, it's going to be incompatible with Rails 4
If we take that idea as the problem, maybe you could detail how you want it to work & we could create a work-around?
try this
C:\Sites\nested>gem install --local automatic_foreign_key
and also bundle install --local in your project terminal and then edit gem "automatic_foreign_key", "~> 1.3.0" in your gem file