NoMethodError undefined method '-#' NoMethodError in Controller Ruby on Rails - ruby-on-rails

Context:
I pulled the most recent code from the repository and tried to make sure that the changes I was about to push up were going to work with that version of the code. This is a Ruby on Rails application. Also worth noting is the fact that when running the main application that I pulled from on the web, this error does not show up. But if I run my branch or the main branch cloned onto my environment, the error always shows up for every url I try. So it is on my end.
Problem:
As soon as I go to localhost:3000, I get the following error:
NoMethodError in HomeController#index
undefined method `-#' for #<ActionDispatch::Response:0x64fd460>
What I've Tried:
I have asked my question on the #rubyonrails IRC channel and nobody was able to determine what was going on through the Full Trace (I haven't posted it here because I wasn't sure what was the best way to do that on here; it didn't look very good in the code block or block quote). I have looked at my HomeController's index method, which is defined as such:
def index
#groups = #current_user.groups
#things = Thing.where(:group_id => #groups.map{|e|e.id})
end
I have also Googled around and haven't found what I need to fix the problem.
What I've Learned So Far:
-# is an operator. Some people may receive a similar error in assuming that Ruby has the shortcut to
variable = variable + 1
that a lot of other languages have:
variable++
Here is an example of that case: Undefined method `+#' for false:FalseClass (NoMethodError) ruby
Question:
Does anyone have any further suggestions on how to find the issue here? Also, if I could easily put the Full Trace on here, formatted in an aesthetically pleasing manner, would someone tell me how? I'm at a loss with this one :(
Update (2/8/2013):
It seems that the issue does not necessarily reside in the HomeController nor home/index.html.erb View. I have attempted to access ANY url with a valid action and the same error occurs with "NoMethodError in..." changing to the corresponding [...]Controller#index.
Update (2/9/2013):
Since this error happens no matter what url I try to navigate to, I decided to look in the routes.rb file in the config folder. I ran my server through rubymine instead of the command line this time, which made it a little easier to read for me. I started looking through all the spit out and I noticed an interested line that consisted of:
["private-key looking thing"] [127.0.0.1] Started GET "/" for 127.0.0.1 at 2013-02-09 18:20:52 -0700
It seems like there is a syntactical error in routes.rb (that's my best guess at this point). This does not explain why this only is an issue on my local environment with the same code sets, but what else do I have to go off of?
Does anyone have any suggested things to be on the look out for while I sift through this file? Not really sure what to be looking for as far as errors are concerned. Rubymines inspection stuff converted all my double quotes to single quotes and doesn't really have anything else to complain about.
Thanks in advance,
Jake Smith

I am guessing it might as well be an syntactical error in the corresponding view page Home/index.html.haml .. I am suspecting there is unintended '-' in front of variable call. I tried to simulate a similar scenario in my rails platform and see following page on browser
undefined method `-#' for false:FalseClass
Correct lines of code
%h1 All Movies
= "filtervalue=#{#isFilterOld}"
= "Sortvalue=#{#isSortOld}"
Edited to simulate the error (observe the - in front of isFilterOld variable)
%h1 All Movies
= "filtervalue=#{-#isFilterOld}"
= "Sortvalue=#{#isSortOld}"

I have fixed the issue!
What fixed it:
Go to the directory where your gems are (for me that was C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1)
Delete all gems except for bundler
Make sure you delete the gems from the /cache/, /gems/, and /specifications/ folders (I just deleted them from the /gems/ folder at first and bundle install indicated that it could still find the gems)
Run bundle install
Further Inquiry:
Does anybody have any idea why this worked? I don't know if at this point I can narrow down which gem was causing the issue because the app is working now (I can visit all the urls with corresponding views). If the issue comes up again, I will delete gems one by one to nail down which one was at least causing the issue for me. But if anyone has any insight on this, a more detailed answer would be greatly appreciated by many more people than just me, I think. Thanks to all who helped thus far!

Related

How can I get Rails to give me more details on an error it's not logging?

This has been stumping me: Rails is throwing this error, after it's finished rendering my views, but before it gets back to the browser:
ActionView::Template::Error (undefined method `start_with?' for #<Proc:0x00005651bfe017f0>)
And... that's it. There's no stack trace. I get shown the standard 500 "We're sorry, but something went wrong" page, despite having config.consider_all_requests_local = true set. There are no further details either in the terminal or in log/development.log.
I can't find any Procs that it might be complaining about, nor can I find any calls to start_with? that might be the cause; I've gone back through Git history and isolated the issue to one commit (this one, if you want to take a look in detail), but nothing within that commit jumps out as being obvious.
Calling a render layout: false does work, as does simplifying my layouts/application.js down to just a <%= yield %>, which makes me think it might be something in there, however - I made no changes to it or any views at all in the commit in which the issue appeared.
What I'd really like to know is how I can get Rails to give me the stack trace for this error, so I can figure out where it's coming from. If you have any ideas where the bug itself might be, those are more than welcome too.
Drop this in an initializer (proc.rb):
class Proc
def start_with?(*args)
puts caller
end
end

Rails: NameError on nonexistent RAILS_ROOT

This is really bizarre. I was following one the answers here just to test things out. I couldn't get it to work out, so I just deleted it. I just have this now:
class DocController < ApplicationController
def index
end
end
I refreshed the page and still had an uninitialized constant DocController::RAILS_ROOT on line 7. I do not have a line 7, it ends at 5. So I decided to put puts "alskjdfal;ksdjfa;lkdsjf" on line 7, and my controller file then ended at line 8. It still said that the error came from line 7. I deleted the controller, but left the route in, and it still says the error comes from line 7. I know it isn't that I'm working on the wrong file, because I can see the changes I make on the error page.
So I figure it's something in the background, but when I tell git to drop all my changes, it still happens, and git says there is nothing different in my files. When I switch to my master branch, which has none of this business, after I add get 'doc/index' to the master routes.rb, I get this same error.
Where is it coming from, and how can I get rid of it? Please and thank you.

Now that ActiveRecord::Base.silence {} is gone, how do I bring back that functionality?

I do a lot of spatial queries that dump massive amounts of text in the form of logs every time I run queries. These slow down my programs enormously.
I'm being forced to update my rails to '4.1.2' from '4.0.0' and ActiveRecord::Base.silence has been completely deprecated as in, it doesn't work. Here's what used to work
ActiveRecord::Base.silence do
noisy_query
end
When I try this now, I get this error....
ArgumentError: wrong number of arguments (0 for 1)
from /Users/davidddouglas/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.1.2/lib/active_support/core_ext/kernel/reporting.rb:82:in `capture'
In 4.0.0 it sent a deprecation warning, and now the script just doesn't work. Oddly enough, the function is still declared, it just doesn't work anymore and expects some kind of parameter. I've tried passing in nil and got this error:
NoMethodError: undefined method `reopen' for nil:NilClass
I'm looking for a way to monkeypatch the old functionality back into my program to get my scripts to work again. Not too worried about best practices as this is an application I'm using internally with little to no front end and 0 users other than myself.
Thanks
silence moved to a core extension on logger.
From their example,
logger = Logger.new("log/development.log")
logger.silence(Logger::INFO) do
logger.debug("In space, no one can hear you scream.")
logger.info("Scream all you want, small mailman!")
end

Rails Controller not picking up matching models and methods

So my Rails controller isn't working (properly) for some reason.
I first noticed something funny when I opened the controller file for the first time.
Compare this to normal syntax highlighting. (Also notice the overly long name)
This was the error I got when I tried to create a link in one of my views.
ActionView::Template::Error (undefined method `new_voyage_at_port_log_entries_path' for #<#<Class:0x007fb1c5921a98>:0x007fb1c81a32a0>):
Here's proof that I inserted this in my routes.
resources :voyage_at_port_log_entries
I do have it working by creating manual routes, but that is a little awkward, and I may forsee problems later. Why might ActionView not be working?
DUH! Routes are created for the singular version.
So...
new_voyage_at_port_log_entry_path
works!
BUT...syntax highlighting is still off...
Hmmm...not important but weird...probably has a different pluralization engine?

Problem with Ruby OmniComplete in Vim 7.3 finding matches at one line but not 2 lines down

Im trying to figure out why ruby omnicompl only works sometimes for me.
Here it's working as expected.
But when I try the same thing on the same ivar 2 lines down I get "Pattern not found"
Both are done the same way, typing out #current_user_session.fiCtrl+X+O
I checked tpopes rails.vim github page for open/closed issues and tried to google it without luck.
My macvim and vim is compiled with +ruby
:echo &omnifunc returns rubycomplete#Complete
:Rails! returns rails.vim 4.3 (Rails-controller)
I have my complete vimdir on github for reference.
one would imagine that it's because in img2 it's now below the setting of the variable (#current_user_session = UserSession.find).
which means that as this is now an instance it's looking for instance methods, whereas before it was returning the class method.
e.g.
User.find # => fine
user = User.find
user.find # => Method not found
to demo the difference run these:
User.methods.sort
User.find.methods.sort
you'll see that it's quite different. put bluntly you're trying to look up 'find' for a user you have. "'tom'.find" doesn't make any sense.

Resources