Ruby on Rails: NoMethodError undefined method `get_yaml' for String - ruby-on-rails

I tried to deploy a non public project but sometimes when tried to use
report pages (based on prawn) I have this problem:
NoMethodError (undefined method `get_yaml' for #<String:0x7fdecffd3738>):
The piece of code is:
report_content = report.draw(report_content.get_yaml)
Someone know: where are get_yaml come from?
Thanks.

The method #get_yaml is not a part of of the standard Ruby library, although #to_yaml is defined if the yaml library has been loaded. #get_yaml, if it exists, is defined by the application or by some library that the application is loading.

Related

undefined method `find_all_by_X'

Currently maintaining some old Ruby server and got the following error in Log:
NoMethodError (undefined method `find_all_by_X_ID' for #<Class:0x00000005555555>):
app/controllers/some_controller.rb:10:in `buggy_function'
When viewed the faulty line in code of the buggy function is looks like this:
Hash[S.find_all_by_X_ID(TaskRun.select(:x_id).uniq.where(y_id: #y.Y_ID).map(&:x_id)).map { |s| [s.S_IDENTIFIER, s.X_ID] }]
To be frank, I'm new to Ruby, and wondering how implementing this find_all_by_X query would be the best, and why it appears as it should be automatic (as it has to do with the model component).
We're working on Ruby version 2.
It seems that find_all_by was deprecated in Rails 4 ...
Internally Rails implemented methods like find_all_by_x_id using method_missing (the method is actually defined dynamically through metaprogramming) ... but you don't have to worry about that for your use-case.
In terms of your code, if we extract the x_ids list into a variable:
x_ids = TaskRun.select(:x_id).uniq.where(y_id: #y.Y_ID).map(&:x_id)
Then you have this line that you need to rewrite:
S.find_all_by_X_ID(x_ids)
You can rewrite this as:
S.where(x_id: x_ids)
See https://stackoverflow.com/a/23921890/2981429

Rails Console 'helper' and 'app' Appear Incomplete

Using ruby 2.3.0 and rails 4.2.5.1, I'm trying to figure some things
out using the rails console. I have several instances where app or helper seem like they have a method I want, but I often end up with the NoMethodError message. This happens even in a brand-new application where I've edited nothing and given no special options to the rails new command. For instance:
irb(main):015:0* helper.timez
... here I hit TAB to get:
irb(main):015:0* helper.timezone
... and hit ENTER, only to find:
NoMethodError: undefined method `timezone' for #<ActionView::Base:0xc662b80>
Why would tab-expansion in the console expand to methods that don't
exist? More importantly, if they're supposed to be there, why aren't
they? What can I be doing wrong?

.to_date method failing

I am using rails 3.2.16 and ruby 1.9.3
I get this error from the localhost browser after rails s.
undefined method `to_date' for nil:NilClass
like this
NoMethodError in Products#new
Showing /Users/main/railscasts-episodes/episode-350/store-
after/app/views/products/_form.html.erb where line #27 raised:
undefined method `to_date' for nil:NilClass
in irb> mode it works only when I
require 'date'
Now my question is about my rails project. In which file in my project I should add
require 'date'
I added it into my model it did not work. Or, maybe I need to install any specific gem? to make this work
The problem you have isn't an issue with to_date, it's a problem with the object you're trying to perform the method on
Your issue will either be:
You have not declared the variable / object
Your variable / object is not populated with any data
I'd highly recommend posting the controller action you're using to invoke the to_date method. Obviously, there may be an issue with the way you're calling it, but the immediate issue is you're trying to deal with an unpopulated variable

Can't create users in rails when using authlogic because of cookies

So, I have a standard rails 3 app with authlogic. If I'm not in the browser (in the console or in the test environment), I can't create user models.
For example:
I have this code either in a rspec test or in my console:
user = User.create(...user attributes...)
And I get this error:
NoMethodError: undefined method `cookies' for main:Object
I've looked all over the internet and can't figure this out. Any help would be greatly appreciated.
EDIT:
So, I looked around some more and found in the documentation to do this:
include Authlogic::TestCase
but then I get this error:
uninitialized constant Authlogic::TestCase
I had this same exact problem. Where in your application did you put the following line:
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
I ran into this error when I placed the line in either the environment.rb file or within a file within my initializer folder.
I eliminated the problem when I placed the line in my ApplicationController instead.

NoMethodError in rails

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

Resources