I have a project totally an api one returning json response. I have an affiliation table associated with other information. All information in my tables is being fetched through rake task. Now the issue is, the project was running fine but not now when I run a rake task it gives an error in .get method as such
NoMethodError: undefined method `get' for #<Class:0xc3ba52c>
/home/munam/.rvm/gems/ruby-2.1.4/gems/activerecord-4.1.6/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
Here I have used it :
#affiliation = Affiliation.get('my_key')
If I change this to
#affiliation = Affiliation.find_by_key('my_key')
It works fine. But unfortunately I do not have access rights to change in it. Moreover I do not understand why has that method stopped working just at a sudden.
I read about this over here:
http://api.rubyonrails.org/v3.2.1/classes/ActiveResource/CustomMethods.html#method-c-get
Can I not make it work some other way:
I really need this integration to work properly. I will be really thankful if someone helps.
Related
I have a simple rails app and I am trying to save and retrieve keys from a memcache box, which was working for a long time unless we started encountering the error below, I have tried debugging this but will need someone to help now
[2015-10-28 12:25:46.649][ERROR] Unexpected exception during Dalli request: NoMethodError: undefined method `<<' for nil:NilClass (pid:58452)
[2015-10-28 12:25:46.649][ERROR] /Users/aupadhyay/.rvm/gems/ruby-2.2.2/gems/celluloid-0.17.2/lib/celluloid/proxy/async.rb:28:in `method_missing'
/Users/aupadhyay/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/core_ext/marshal.rb:6:in `load'
Let me know incase anyone has insights to this ?
I'm working on a Ruby 1.8 / Rails 2.1 application which is connecting to a SQL Server 2008 database.
When I try to use a find_by_CompanyCode method, ActiveRecord returns a NoMethodError. Yet, from the following you can see that the table exists and has the method in question.
Not sure what I'm missing.. any help would be appreciated
EDIT: Only fields which end in "Code" aren't appearing when I just run IvantageEmployee.first .. error occurs from a view. Moving the exact same code to a controller, the code works as expected.
eval #goal.organization_type.employee_class + ".find_by_#{#goal.organization_type.employee_field_code}('#{#goal.specifier}').#{#goal.organization_type.employee_field_description}"
>> IvantageEmployee.first.CompanyCode
=> "GAI"
>> IvantageEmployee.find_by_CompanyCode('GAI')
NoMethodError: undefined method `find_by_CompanyCode' for IvantageEmployee(Table doesn't exist):Class
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1613:in `method_missing_without_paginate'
from /usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing'
from (irb):7
>>
Some more information. The table has several fields. The one I'm struggling with is CompanyCode, but it also has RegionDescription.
Note the following console output. find_by_RegionDescription works; find_by_CompanyCode doesn't work. Also, CompanyCode doesn't appear when I just output the class, but RegionDescription doesn't Not sure why ActiveRecord would be missing fields that are on the table
>> IvantageEmployee.find_by_RegionDescription 'GAI'
### Finding method find_by_RegionDescription
=> nil
>> IvantageEmployee.find_by_CompanyCode 'GAI'
### Finding method find_by_CompanyCode
NoMethodError: undefined method `find_by_CompanyCode' for IvantageEmployee(Table doesn't exist):Class
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1614:in `method_missing_without_paginate'
from /usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing'
from (irb):9
>>
You need to use snake case instead of camel case:
IvantageEmployee.find_by_company_code('GAI')
The convention in ruby is to use camel case for classes and snake case for methods. Rails follows that convention(as should you) so you can assume that any methods dynamically created by it are going to be snake case.
i am using rails_admin. when i go to certain resource. by typin url
localhost:3000/admin/rule
than it give me this error. code is:
scope = Rule.all
scope.page(1).per(2)
. above code is writtten in rails_admin gem.in a file named mongoid.rb placed in adaptors folder. complete log is:
NoMethodError (undefined method `page' for #<Array:0xcea7408>):
mongoid (2.4.8) lib/mongoid/criteria.rb:385:in `method_missing'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/kaminari-809105ad782a/lib/kaminari/models/mongoid_extension.rb:11:in `page'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/lib/rails_admin/adapters/mongoid.rb:37:in `all'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/app/controllers/rails_admin/main_controller.rb:127:in `get_collection'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/app/controllers/rails_admin/main_controller.rb:39:in `list_entries'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/lib/rails_admin/config/actions/index.rb:30:in `block (2 levels) in <class:Index>'
what should i do to resolve this error?
You can not call Kaminari methods on Array, because Rule.all will return Array.
So you have to do something like this: Rule.page(1).per(2)
Here is documentation and examples of Kaminari usage:
https://github.com/amatsuda/kaminari
I've been running into this issue off and on for a while now using Mongoid. Sometimes refreshing the page in RailsAdmin would fix it.
I figured out that the problem is Kaminari's hooks are not initialized in my environment, so the models that rely on Kaminari's extension methods don't have them available.
I simply took the following line from Kaminari's railtie and put it at the top of my rails_admin initializer:
Kaminari::Hooks.init
Now things seem to be working for me. However, I don't know why the ActiveSupport callback is not running that code.
Use this
Kaminari.paginate_array(Rule.all).page(params[:page])
Kader's solution is great! The only thing is I found I have to add .per to make it work.
Kaminari.paginate_array(Rule.all).page(params[:page]).per(PER_PAGE_RECORDS)
I am creating a new environment besides production. I copied all the configurations from my production environment, changing what needed to be changed.
As it is the servers do start, but when I do a query I get this exception:
NoMethodError (undefined method `use_slug?' for nil:NilClass):
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:65:in `slugged?'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:43:in `finder_class'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:37:in `finder'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:32:in `method_missing'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/slugged_model.rb:149:in `find_one'
app/controllers/home_controller.rb:5:in `index'
The line in question does this:
#page = Page.find("home")
I am using FriendlyId 2.3.4, and Rails 2.3.4. The code is the same for the production environment, and it's working just fine there, so I'm not really sure on what's going on here...I could see that the line where the exception gets raised does
friendly_id_config.use_slug?
so for a reason I'm not aware of friendly_id_config is nil.
Thanks for any guidance on this problem
I found a workaround to this issue by loading the server using the production environment.
I was trying to use a 'preprod environment, and somehow FriendlyId didn't like that strange environment.
Load the app using RAILS_ENV=production and it worked fine.
Not a solution, but at least could move on...
The extracted source is below :
Showing /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/templates/rescues/diagnostics.erb where line # raised:
private method `gsub' called for #<NoMethodError: undefined method `closed?' for nil:NilClass>
Extracted source (around line #):
RAILS_ROOT: /home/sharath/Desktop/RORWorkspace/ITPLOW1
It was working before installing Sunspot: A Solr-Powered Search Engine for Ruby.
I am working in Ubuntu 10.04.
I'd need to see the full stacktrace to be sure, but this is actually probably an unhelpful HTTP connection error message bubbling up out of RSolr (the library the Sunspot uses for the low-level Solr connection). Is Solr running (i.e., did you run rake sunspot:solr:start)? Can you access http://localhost:8982/solr/admin ?
What's probably happening is you're attempting to do a substitution on some variable which you thought you were initializing, but neglected to give a real value.
For instance, if you had a form where for a Message and one of the the properties you want is the content, you would normally retrieve that information in the controller with
params[:message][:content]
And if you wanted to filter it, you would do something like
params[:message][:content].gsub(/<[^>]*>/,"")
But if the user didn't enter anything into the content field, the params[:message][:content] variable wouldn't be set. Therefore it's null and you're attempting to do nil.gsub