If a project is running Rails 2.2.2, and it uses controller.helper and the helper is not defined, then how can it be solved? (this is for the Facebooker2 gem http://github.com/mmangino/facebooker2)
details:
error shown:
=> Rails 2.2.2 application starting on http://0.0.0.0:3000
Exiting
/Library/
Ruby/
Gems/1.8/gems/facebooker2-0.0.5/lib/facebooker2/rails/controller.rb:8:
in `included': undefined method `helper' for Object:Class (NoMethodError)
The code is: error line is line 8:
controller.helper Facebooker2::Rails::Helpers
in the following code:
module Facebooker2
module Rails
module Controller
def self.included(controller)
controller.helper Facebooker2::Rails::Helpers
controller.helper_method :current_facebook_user
controller.helper_method :current_facebook_client
controller.helper_method :facebook_params
end
Related
I have a Rails application, recently I changed my database from MySql to PostgreSql, from then onwards active-records import method :on_duplicate_key_update is throwing an error.
def import_of_products(import_links)
Product.import import_links, :on_duplicate_key_update => [:ad_id]
end
The error showing is,
NoMethodError: undefined method `sql_for_on_duplicate_key_update' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0xab19f90>
from /home/mysystem/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-import-0.4.1/lib/activerecord-import/adapters/abstract_adapter.rb:48:in `post_sql_statements'
I'm running:
Rails version: 4.0.2
Ruby version: 2.0.0p643
I am using Kaminari 0.16.3 with Rails 4.2.0. Not sure what is going wrong, I have pasted code run by me in console, which proves kaminari gem is loaded but page method is undefined on ActiveRecord model.
abhishek#abhishek ~/my_app (master●●)$ rails c [ruby-2.1.5p273]
Loading development environment (Rails 4.2.0)
irb(main):001:0> Kaminari
=> Kaminari
irb(main):002:0> User.page
NoMethodError: undefined method `page' for User (call 'User.connection' to establish a connection):Class
Please note: I am intentionally calling page without any arguments to reproduce the issue.
Due to an issue with will_paginate and rails_admin I had this in my codebase causing the page method to be renamed to per_page_kaminari.
I have realized this late and fixed.
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
Have a look at this tutorial https://github.com/amatsuda/kaminari
This is how it works
User.page(page_number).per(records_per_page)
Where does the call to the isolation_level come from?
My module fails at a.save!
module AppsHelpers
def self.create_app!
a = App.new
a.save!
a
end
end
The specific NoMethodError:
Failure/Error: #app = AppsHelpers::create_app!
NoMethodError:
undefined method `isolation_level' for ActiveRecord::Base:Class
What could possibly cause this failure?
System:
ruby 1.9.3p448
Rails 3.2.8
This was simple. I was calling a method defined in the Transactional Isolation gem: The stacktrace was not helpful because I was calling it from an installed gem and this was a missing dependency.
I'm updating the code for a generator that I wrote, but has been working fine until now.
When I simply rue the command
bundle exec rails g
I get the following error
/Users/mpierc200/projects/prototype_conflux/vendor/gems/itrc_client_files_generator-1.0.13/lib/itrc_client_files_generator.rb:6:in `<top (required)>':
uninitialized constant Rails::Generators (NameError)
The offending line is
class ItrcClientFilesGenerator < Rails::Generators::Base
My Rails version is
Rails 3.1.9
ruby version is
ruby 1.9.3p194
It looks like the Rails generator modules were pulled out and not automatically loaded at some point during Rails 3 development. This is probably for good reasons.
You have to include them in custom generators:
require 'rails/generators'
class ItrcClientFilesGenerator < Rails::Generators::Base
# Fancy generator code here
end
Previously I haven't got such a problem with Rails 2.3.2 installation. Somebody have any suggestions how can I fix that?
`$ ruby script/server
=> Booting WEBrick
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/rails/gem_dependency.rb:99:in 'requirement': undefined local variable or method 'version_requirements' for # (NameError)
from /home/thesis/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems.rb:254:in 'activate'
from /home/thesis/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems.rb:1204:in 'gem'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/rails/gem_dependency.rb:57:in 'add_load_paths'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/initializer.rb:299:in 'add_gem_load_paths'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/initializer.rb:299:in 'each'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/initializer.rb:299:in 'add_gem_load_paths'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/initializer.rb:132:in 'process'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/initializer.rb:113:in 'send'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/initializer.rb:113:in 'run'
from /home/thesis/development/tt/my_app/config/environment.rb:15
from /home/thesis/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in 'gem_original_require'
from /home/thesis/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in 'require'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in 'require'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in 'new_constants_in'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in 'require'
from /home/thesis/.rvm/gems/ruby-1.8.7-p334#my_app/gems/rails-2.3.2/lib/commands/server.rb:84
from /home/thesis/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in 'gem_original_require'
from /home/thesis/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in 'require'
from script/server:3`
put below code in your environment.rb. it might be solved your problem
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end