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.
Related
I'm trying to use my Engine in another app to test the install generator and it seems to be failing. I haven't used my install generator for a long time, so I'm not sure when it broke (or if it ever truly smoothly worked). My project is based off radar/forem, so I tried to borrow a lot of their code (including the generator).
Edit: My installer works for the engines test/dummy but not in other apps. Why?
GH issue: https://github.com/NJayDevelopment/mongoid_forums/issues/16
Here is the log:
$ rails g mongoid_forums:install
What is your user class called? [User]
What is the current_user helper called in your app? [current_user]
Defining mongoid_forums_user method inside ApplicationController...
insert app/controllers/application_controller.rb
Adding mongoid_forums initializer (config/initializers/mongoid_forums.rb)...
create config/initializers/mongoid_forums.rb
(erb):5:in `template': undefined method `per_page' for MongoidForums:Module (NoMethodError)
The route is successfully added, however the initializer/mongoid_forums.rb is a blank file. The method is defined exactly how radar/forem does it, what could be the error?
Here is the relevant code:
Per page method definition: https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/mongoid_forums.rb#L33
Mattr accessor:
https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/mongoid_forums.rb#L9
Initializer template:
https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/generators/mongoid_forums/install/templates/initializer.rb
Install generator at error point:
https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/generators/mongoid_forums/install_generator.rb#L47
Turns out when you try requiring mongoid_forums in pry, you'll see that an error involving decorators occurs. The issue is fixed here in my pull request to decorators: parndt/decorators#13
It's because of the way files are required and how load! is called over there.
Waiting on PR status, that is the same version that radar/forem uses as well.
I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315, yet the vaguely described solution is not working for me. When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s:
...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)
If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. I don't fully understand the initialization process, so am not sure how to go about getting this to work.
I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. I also have the following line in my initializer:
config.included_models = [Listing,ListingImage,AllOtherModelsHere...]
I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here
[RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)
Any ideas what else I can try to make these gems work together? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration...
Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too:
Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin.
I run into several weird problems trying to set this up. For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error.
So what I end up doing was:
class MyModel < ActiveRecord::Base
include Impressionist::IsImpressionable
is_impressionable
end
So this solved my issue and now i can access #my_model_instance.impression_count as expected.
I changed every occurrence of Klass to 'Klass'.constantize in initializer.
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've been trying to use the code here:
http://snafu.diarrhea.ch/blog/article/4-serving-static-content-with-rails
but I'm getting errors like:
undefined method `template_exists?' for #<StaticController:0xb74cbe4c>
How can I update this method to Rails 2.5? Probably there are other deprecated things too.
The method call template_exists? is deprecated as of Rails 2.2.1 (see: Rails APIdock)
A little bit of digging revealed the solution, by the original author, in the following article article. Basically requires adding the method into the StaticController, derived from ApplicationController and thus gives the method.