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?
Related
O.k. this is driving me crazy - if anyone could help that would be great.
I have a simple table "threads" with an auto id and a "name" field with one record (id = 1, name = "space").
I have a model named "Thread.rb".
class Thread < ActiveRecord::Base
end
I have a controller that calls:
#thread = Thread.find_by_id(1)
But when loading a page I get the following error in the controller:
undefined method `find_by_id' for Thread:Class
I've used find_by_sql numerous times in the same project with no problem, but when using the simple activerecord accessors rails errors out on "find", "find_by_id" etc.
I'm on rails 4.0.2
I'm pretty sure Thread is a reserved word in Rails, I recall having the same issue. Renaming your class should solve it. I was able to find this community authored site with a list of reserved Rails words.
rails has the autoloading mechanism by hooking into the const_missing and the combination of some convention on constant naming and autoload_paths.
If you refer to a constant that is already predefined, either in the ruby standard library or the rails, then it will refer that constant to the already loaded one.
Thread is part of ruby standard library, which is why when you say Thread.find_by_id(1), it is referring to that instead of your model.
Refer to Thread and Module#const_missing for more info.
So I have this model object Shop::Order, which has worked fine until now.
But today I get these weird errors in my forms Undefined method 'model_name' for Shop::Order:Class.
So I look around and test in my console, that all instances of Shop::Order don't have any persistence methods. But still my tests don't fail. So I load up the test console and there Shop::Order works perfectly.
This doesn't really make any sense to me and I'm quite frankly out of Ideas on how to solve this.
Here's a link to the model: Shop::Order
The error appears in this view: new.html.haml
All other models are working totally fine.
Any help would be appreciated.
The problem lays in config/initializers/contants.rb where you're predefining your Shop::Order class.
I assume what happens is, the autoloader does not search further once it already has the class defined.
You should remove it, as this is not the initializer use case to define model's constants.
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!
I was trying to make work this:
http://chainselects.hypermediasoft.com/
But got error:
Routing Error
uninitialized constant ChainSelectsHelper
So i have to make some break and ask community - is there any easy way to make chaining select boxes for my application forms?
UPDATE:
Maybe i should make editions in some config files? I can see thist ChainSelectsHelper in vendor/plugins/ChainSelects/lib/app/helpers/chain_selects_helper.rb. But why my application can't see this? Any assets pipeline configs needed?
And got this error in model:
undefined method `acts_as_chainable' for #<Class:0x007fe387542780>
From the looks of it, it seems that you did not add this in the controller:
include ChainSelectsHelper
Keep in mind that modifications have to be made to both model and controller, as stated here.
I'm in the process of upgrading an app to Rails 3/Rspec 2. I see that
stubbing a view helper method has changed in Rspec 2. It looks like
instead of doing template.stub!, we're now supposed to do view.stub!,
but I can't seem to get this to work on beta 10. I get an "undefined
local variable or method `view' for # < RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x106785fd0>"
error.
I see that in this commit David removed the view
method, but I can't figure out what it was replaced with. Something
in ActionView::TestCase::Behavior?
I'm on rails 3.0.0.beta3.
Any idea what I'm missing?
This turned out to be a bug in rspec-rails after moving more of the functionality back to ActionView::TestCase::Behavior. David re-exposed _view as view, so view.stub! is still the way to go. It was just temporarily broken.