Rails 4.2.3, IdentityCache gem 0.2.5
I am calling ZipCodeLookup.fetch_by_id(value) and I am getting the following error:
undefined method `fetch_value' for #<Hash:0x007fbc6d261e08>
I have the following attributes in my ZipCodeLookup model
include IdentityCache
cache_index :zip_code, unique: true
I haven't seen anyone else with this issue. Does anyone know how to fix this?
fyi works in Rails 4.1.x
the error came from not clearing the cache. so run the following command in the rails console: IdentityCache.cache.clear
I've seen the same exception before without using IdentityCache. In my case, some ActiveRecord models were manually marshaled via Marshal::dump and saved as binary stream. Then, Ruby and Rails were upgraded.
Afterwards, calling Marshal::load on the marshaled copies would retrieve them and object.class would show the right model's name, but accessing any attribute within would throw the same exception.
I had to clear the marshaled copies and generate new ones.
Related
I have upgraded my Ruby to 2.5 and after rectifying many dependency issues, I'm stuck at a place.
There is save method being called which saves the records, but somehow it do not works now and shows following error:
500 Internal Error
undefined method 'fetch_value' for #<Hash:0*0007e589e>
Did you mean fetch_values
each_value:
Earlier the same .save was working perfectly fine.
I've seen the same exception before. In my case, some ActiveRecord models were marshaled via Marshal::dump and saved as binary stream. Then, Ruby and Rails were upgraded.
Afterwards, calling Marshal::load on the marshaled copies would retrieve them and object.class would show the right model's name, but accessing any attribute within would throw the same exception.
I had to clear the marshaled copies and generate new ones.
I updated my company's application from Rails 5.2.1 to Rails 5.2.2.1. Upon running our test suite post-update, I am encountering issues with validating uniqueness within the scope of a model, specifically, when appending a model to the ActiveRecord relation of another model. For example, in our application, if I were to do #person.cars << #car, we would run a uniqueness validation (validates :car_id, uniqueness: { scope: :group_id }. Even in a scenario where #person.cars was originally empty, our post-update branch is throwing validation errors on this uniqueness check. These test cases work on our master branch (pre-update), but not on our update branch (post-update). There have been no other changes made to the application besides updating Rails from 5.2.1 to 5.2.2.1. I am wondering if anyone knows of any existing bugs or issues in relation to Rails 5.2.2.1 uniqueness validations that may be causing this. I have looked through the changelogs of both Rails and ActiveRecord, as well as a few other dependencies that were updated, but I have been unable to find anything.
Looks like this is an issue with a change made in Rail's ActiveRecord::Associations which used to remove duplicates in version 5.2.1, when appending to an ActiveRecord association. This never threw a RecordInvalid exception, as the duplicate would be removed before hand. In 5.2.2.1, it looks like that has been removed, and any duplicates appending to an association will no longer be preemptively deleted (most likely to mimic Ruby += functionality). I had to change all your uses of += to a relation to |= to ensure duplicates were no longer being appended on.
Sorry for no being able to post any code or stack traces. The stack trace was very application specific and wouldn't have been helpful at all, and the code is proprietary. Appreciate the help!
I have a query object in Rails 5.2.2
app/queries/car_query.rb
class CarQuery
attr_reader :relation
# code
end
when I reference it in the console, I get
Error
NameError (uninitialized constant CarQuery)
Since the folder/file is in the app directory, I thought it automatically gets loaded. Am I incorrect? If so, why would my form objects autoload and not these? How do I fix this?
Try running bin/spring stop in your console then restarting the app.
If that doesn't work add update you application.rb with
Spring.watch "app/queries/**"
Make sure that the name of the file corresponds to the class name, or else rails will have trouble loading it. That is to say, make sure the file name is car_query.rb, if CarQuery is the name of the class.
CarQuery.rb goes against rails naming conventions and will mess with autoloading.
I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315, yet the vaguely described solution is not working for me. When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s:
...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)
If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. I don't fully understand the initialization process, so am not sure how to go about getting this to work.
I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. I also have the following line in my initializer:
config.included_models = [Listing,ListingImage,AllOtherModelsHere...]
I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here
[RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)
Any ideas what else I can try to make these gems work together? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration...
Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too:
Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin.
I run into several weird problems trying to set this up. For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error.
So what I end up doing was:
class MyModel < ActiveRecord::Base
include Impressionist::IsImpressionable
is_impressionable
end
So this solved my issue and now i can access #my_model_instance.impression_count as expected.
I changed every occurrence of Klass to 'Klass'.constantize in initializer.
I ran a migration on an Image model to add the column Position.
The schema is updated, the column has actually been added to the database, and is accessible through Rails console. I'm even calling an order by clause using that column in ActiveAdmin, and that doesn't grumble .
However when trying to access that attribute in the app, I'm presented with unknown attribute errors.
When trying to display the column in an ActiveAdmin index view, I get:
undefined method `position' for #<Image:0x007f8a3429be98>
It (position) has been added to attr_accessible too.
I've also run:
Image.connection.schema_cache.clear!
Image.reset_column_information
and that hasn't helped either.
Rails 3.2.12
After some searching and trying I was able to reproduce the error it was triggered by a before filter.
This post led me to the solution:
Undefined method "reorder" for #<Array:0xbc38600> using ActiveAdmin
when it helped please upvote the other comment.