I am updating from Rails 3 to Rails 4.2, and when I run my application's test suite, I get the following error:
Failure/Error: get 'edit', id: #shops[3].id
NoMethodError:
undefined method `map!' for #<Shop::ActiveRecord_Relation:0x007ff1d69b4f40>
The code in the controller is:
existing_shops.map! { |obj| [["##{obj[:shop_id]} #{obj[:name]},
#{obj[:phone]}, #{obj[:address]}, #{obj[:city]}, #{obj[:state]}, #{obj[:zipcode]} "]]}
I am using Rails 4.2.4 and RSpec 3.3.0.
Relation no longer has mutator methods like #map! and #delete_if. Convert to an Array by calling #to_a before using these methods.
existing_shops.to_a.map! { ... }
— A Guide for Upgrading Ruby on Rails
Related
I'm running into this error when upgrading from Rails 6.0.3 to 6.1:
NoMethodError:
undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::EmailJob:0x00005572d8a00758>
Did you mean? assert_raises
This happens every time a test calls perform_enqueued_jobs.
I'm using RSpec 3.9.
Apparently assert_nothing_raised is a helper method defined by ActiveSupport. I was able to solve this issue by explicitly including the helper in spec/rails_helper.rb:
RSpec.configure do |config|
config.include(ActiveSupport::Testing::Assertions)
# ...
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)
I am having errors when using the where method
Project.where('projectid=10').first
It give me this :
NoMethodError: undefined method
where' for #<Class:0xb6ee1144>
from /home/rvb/2011/January/desaldata/vendor/rails/activerecord/lib/active_record/base.rb:1672:in
method_missing_without_paginate'
from /home/rvb/2011/January/desaldata/vendor/gems/mislav-will_paginate-2.3.6/lib/will_paginate/finder.rb:167:in `method_missing'
from (irb):3
I'm using Rails 2.1.1 .. Is the where method not available in this rails version?
'Where' method is only available in rails 3.0.0 or above....
If you do upgrade to Rails (or just ActiveRecord) 3.0, change your query to this:
Project.where(:projectid => 10).first
Also, change the name of 'projects'.'projectid', to 'projects'.'id'.
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