NoMethodError undefined method '- @' NoMethodError in a Ruby on Rails controller

Context: I pulled the latest code from the repository and tried to make sure that the changes I was about to push would work with this version of the code. This is a Ruby on Rails application. It is also worth noting the fact that when I launch the main application that I pulled from the Internet, this error does not appear. But if I run my branch or the main branch cloned into my environment, an error always appears for every URL that I am trying to execute. So this is at my end.

Problem: As soon as I switch to localhost: 3000, I get the following error:

NoMethodError in HomeController#index undefined method ` -@ ' for #<ActionDispatch::Response:0x64fd460> 

What I tried: I asked my question on the IRC channel # rubyonrails, and no one could determine what was going on through Full Trace (I did not post it here because I was not sure if this was the best way to do it here; it didn’t look very good in code block or block). I looked at my HomeController 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 also googled around and did not find what I needed to solve the problem.

What I learned so far: - @ - operator. Some people might get a similar error, assuming Ruby has a shortcut to

  variable = variable + 1 

that many other languages ​​have:

  variable++ 

Here is an example of this case: Undefined `+ @ 'method for false: FalseClass (NoMethodError) ruby

Question: Does anyone have any further suggestions on how to find the problem here? Also, if I could easily turn on Full Trace here, formatted in an aesthetically pleasing manner, would someone tell me how to do this? I'm in trouble with this :(

Update (2/8/2013): It seems that the problem is not necessarily found in the HomeController and home / index.html.erb View. I tried to access ANY url with a valid action, and with the error "NoMethodError in ..." with the same error, the transition to the corresponding index [...] Controller # occurs.

Update (2/9/2013): Since this error occurs no matter what url I try to go to, I decided to look in the routes.rb file in the config folder. This time I started my server through Rubyin instead of the command line, which made it a little easier to read for me. I started looking through all the words, and I noticed an interesting line consisting of:

 ["private-key looking thing"] [127.0.0.1] Started GET "/" for 127.0.0.1 at 2013-02-09 18:20:52 -0700 

There seems to be a syntax error in routes.rb (this is my best guess at this point). This does not explain why this is only a problem in my local environment with the same sets of code, but what else do I need to get away?

Does anyone have any suggested things to keep abreast while I sift this file? Not quite sure what to look for regarding errors. Rubymines inspection materials turned all of my double quotes into single quotes and really don't have anything else to complain about.

Thanks in advance, Jake Smith

+4
source share
2 answers

I fixed the problem!

What is fixed:

  • Go to the directory where your gems are (for me it's C: \ RailsInstaller \ Ruby1.9.3 \ lib \ ruby ​​\ gems \ 1.9.1)
  • Remove all gems except bundles
  • Make sure you remove the gems from / cache /, / gems / and / specification / folders (I just deleted them from the / gems / folder folder and bundle install indicated that it could still find the gems)
  • Run bundle install

Further request:

Does anyone have any idea why this worked? I don’t know if at this moment I can narrow down which stone caused the problem because the application is working now (I can view all the URLs with the corresponding views). If the problem arises again, I will remove the gemstones one by one to nail which one at least caused the problem for me. But if someone has an idea about this, a more detailed answer would be greatly appreciated by many other people than just me, I think. Thanks to everyone who has helped so far!

+1
source

I suppose this could also be a syntax error on the corresponding page in the Home / index.html.haml view. I suspect there is an unintentional '-' before the variable is called. I tried to simulate a similar scenario in my rails platform and see the next page in the browser

 undefined method ` -@ ' for false:FalseClass 

Valid lines of code

 %h1 All Movies = "filtervalue=#{@isFilterOld}" = "Sortvalue=#{@isSortOld}" 

Edited to model errors (watch - before the variable isFilterOld)

  %h1 All Movies = "filtervalue=#{ -@isFilterOld }" = "Sortvalue=#{@isSortOld}" 
+1
source

All Articles