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
Related
I am working with Rails 5.0.0.beta3 and creating a rails-api. when i run
rails-api generate scaffold user email:string password:string auth_token:string
it shows the error
.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'rails-api'. (Bundler::GemRequireError)
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /home/ahsanul/Documents/rails-api/my_blog/config/application.rb:7:in `<top (required)>'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:82:in `require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:82:in `preload'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:143:in `serve'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:131:in `block in run'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:125:in `loop'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:125:in `run'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ahsanul/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ahsanul/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
How can i resolve the problem?
You don't need to include rails-api gem in your Rails 5 app's Gemfile. It's already merged into Rails 5.
Reference
I tried all the above suggestion from Babar but didn't work, so i tried one little thing that work which is adding gem 'listen' to the gem file.
it works for me!!
rails-api generate scaffold user email:string password:string auth_token:string
No need of writing rails-api, just use rails. Rails::API has been merged into Rails 5.0, so no need of gem 'rails-api'.So remove it from gemfile.After than you may get error when you try to migrate.So you have to include listen gem.
in my app , I am using spree gem. Now for product importing ,i used spree_import_products gem.
first i add "gem 'import_products', :git => 'git://github.com/joshmcarthur/spree-import-products.git'
then bundle install" in gem file.then run bundle install, it successfully installed. then run "rake import_products:install".but it shows error like this....
rake aborted!
NameError: uninitialized constant Spree::ThemeSupport
/home/ec2-user/.rvm/gems/ruby-2.2.1/bundler/gems/spree-import-products-2bcca17f140f/lib/import_products_hooks.rb:1:in `<top (required)>'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/home/ec2-user/.rvm/gems/ruby-2.2.1/bundler/gems/spree-import-products-2bcca17f140f/lib/import_products.rb:2:in `<top (required)>'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require'
/home/ec2-user/.rvm/gems/ruby-2.2.1/gems/bundler-1.10.6/lib/bundler.rb:134:in `require'
how to resolve this...
You can check here that this extension requires a very old version of Spree and Ruby. It does not have tests. The problem is the extension itself. Look for another extension or implementing yourself.
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.
So, when running
[leap_staging]$rails g reputation_system
After including the gem 'activerecord-reputation-system', require: 'reputation_system' in my Gemfile I get the below error:
/usr/local/rvm/gems/ruby-2.0.0-p195/gems/activemodel-4.0.0/lib/active_model/deprecated_mass_assignment_security.rb:14:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:25:in `<class:Evaluation>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:18:in `<module:ReputationSystem>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:17:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system.rb:25:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /Users/apane/Downloads/leap_staging/leap_staging/config/application.rb:7:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands.rb:44:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
It's clear to me that this had to with Rails 4 and the new Strong Params. However, I'd like to get this workin'. So, how can I get this to work or convert it to strong_params if I can't even generate the files?
See the full app here if necessary for easy troubleshooting: www.github.com/apane/leap (gem not included)
Have you tried adding the protected_attributes Gem into your Gemfile like the message says?
activerecord-reputation-system gem now supports Rails 4 (since version 3.0).
When I try to run 'rails server' it's giving me an error saying that it can't find 'jcode', and I think jcode is a default ruby lib.
Do you guys have any clue as to whats going on?
/Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/gdata-1.1.1/lib/gdata.rb:21:in `require': no such file to load -- jcode (LoadError)
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/gdata-1.1.1/lib/gdata.rb:21:in `<top (required)>'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/contacts-1.2.4/lib/contacts/gmail.rb:1:in `require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/contacts-1.2.4/lib/contacts/gmail.rb:1:in `<top (required)>'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/contacts-1.2.4/lib/contacts.rb:6:in `require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/contacts-1.2.4/lib/contacts.rb:6:in `<top (required)>'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler/runtime.rb:64:in `require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler/runtime.rb:64:in `block (2 levels) in require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler/runtime.rb:62:in `each'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler/runtime.rb:62:in `block in require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler/runtime.rb:51:in `each'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler/runtime.rb:51:in `require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/bundler-1.0.3/lib/bundler.rb:112:in `require'
from /Users/seanfchan/RubyPractice/gettingContancts/config/application.rb:7:in `<top (required)>'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/railties-3.0.1/lib/rails/commands.rb:28:in `require'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/railties-3.0.1/lib/rails/commands.rb:28:in `block in <top (required)>'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/railties-3.0.1/lib/rails/commands.rb:27:in `tap'
from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0#global/gems/railties-3.0.1/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
System: Mac OSx Snow Leopard
Ruby: RVM 1.9.2
Rails: 3.0.1
Gem: 1.3.7
trying to use 'contacts' gem
Thanks,
Sean Chan
Sounds like the library you're using wasn't updated for Ruby 1.9.
Ruby >= 1.9 doesn't have jcode, a module to handle japanese (EUC/SJIS) strings, as it supports unicode natively.
You may want to see of a newer version of the library is available, otherwise you can look at the source and find where it is requiring jcode, and replace it with
require 'jcode' if RUBY_VERSION < '1.9'
We should check the lib folder which is presented under the gdata gem file.
Add this line:
require 'jcode' if RUBY_VERSION < '1.9'
in the lib/gdata.rb file.
Other solution, put this in your gemfile:
gem 'gdata_19', '1.1.5'
gem 'contacts', :git => 'git#github.com:eofferma/contacts.git'