I’ve recently went back to an old project and it seems to have stopped working giving me this error:
|
1 |
~/projectx/vendor/ruby/1.9.1/gems/devise-2.0.0/lib/devise/rails/routes.rb:391:in <code>raise_no_devise_method_error!': User does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError) |
[read full stack trace at: gist]
Since I didn't really change anything, I was surprised to see it break. So I tried to do what it said, I changed that I had a require statement for my ORM which was Mongoid. I had: (in config/devise.rb)
|
1 2 3 4 5 6 7 8 |
Devise.setup do |config|
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/mongoid'
# ... more settings ...
end |
But that wasn't working, so I tried to move it to my config/application.rb before the definition:
|
1 2 3 4 5 6 7 |
# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require 'devise/orm/mongoid' |
Doing that it just produced:
|
1 |
~/projectx/vendor/ruby/1.9.1/gems/orm_adapter-0.0.6/lib/orm_adapter/adapters/mongoid.rb:6:in </code><module:ClassMethods>': uninitialized constant Mongoid::Document::ClassMethods::OrmAdapter (NameError) |
[read full stack trace at: gist]
So that wasn’t getting me anywhere.
Since really neither of the errors resulted in any information that could help me, I started looking at what I can do to maybe change the issue. I tried updating the gems like devise and mongoid but that didn’t do anything. Now I wouldn’t recommend people do this but I decided to update my app from Rails 3.0 to Rails 3.2, hoping the issue gets solved with that, plus I knew this app was slated to be updated to 3.2 in the near future anyways. So I did that and it didn’t help at all. I walked away from the app for a few days because I knew pulling my hair out wouldn’t get me anywhere.
Today I looked at the app again and still had no idea what was wrong, but I looked at my Gemfile and noticed that I had some unneeded gems for Rails 3.2. Gems like jammit, rails-3-generators and active_reload. After running ‘bundle install’ the app booted up without errors! Reinstalled the gems one by one I found out that active_reload was the reason it was happening.
If you’re getting of the errors that I was seeing and you’ve ensured that everything is setup correctly, try removing active_reload and see if that helps!
Learn MoreWhile working hard at getting an application up and running for a lunch tomorrow, I ran into this annoying screen:

So I re-read the message and followed the included link from the message and found this:

Well it seems that chrome has a built-in DDoS protection, meaning that if a server returns a 500 type error, and you keep refreshing the page to see if it has been fix, chrome will actually stop you for a few second (The exact delay is based on how many times you’ve attempted to access the page “delay = initial_backoff * multiply_factor^(effective_failure_count - 1) * Uniform(1 - jitter_factor, 1]“. Get more info at: http://dev.chromium.org/throttling). This intern stops you from putting extra load on the server while (hopefully) the app is getting fixed.
Now I think it’s great that chrome attempts to stop (probably unintentional) DDoS attacks, but it should really ensure that local requests don’t fall under that protection. I am a developer and I’m trying to fix a local app, which is throwing a 500 error, and I refresh frequently to see if I’ve been able to fix it but when I am delayed before able to see my results, it’s just very unproductive, especially when the delay gets longer with the increasing number of refreshes.
That’s just my thoughts on this. I’ve already let the Chrome team know about this issue. Let me know if you’ve had a similar experience.
I just got an email from Jói on the Google Chrome team and he says:
From version 13 onwards, Chrome should not throttle any requests to localhost or its many aliases (localhostv6, 127.0.0.1, ::1 and so forth). You can check your version by typing about:version into the address bar, but it’s highly likely you are on 14 or later.
On the other hand, it is very difficult for Chrome to distinguish that a domain name or IP address other than the ones universally recognized as being the local loopback address actually points to the local server.
And so it seems because I’m using Pow and my URLs look like http://myapp.dev, chrome is unable to determine if this is a local request and therefore kicks in the DDoS prevention.
Learn MoreI recently updated one of my apps to Rails 3.1 and found that my PDF generating tests were failing because they were unable to find the CSS or images to use in the PDF.
So I started playing around, and here is what I got:
In your app, add a new initializer (or edit your existing wicked_pdf.rb initializer) and put the following:
As you can see in the code, I also replaced the background urls with correct references, this is assuming that you’re keeping your CSS images in the same location as your normal images (which I don’t see a reason why not but of course you can always tweak the script)
I had one issue with my generated PDF using pow.cx, my CPU would jump to 100% (on the pow process) and the page would timeout. After upgrading to the latest version of pow (0.3.2) using this command:
|
1 |
curl get.pow.cx | sh |
I was able to see my PDFs without an issue.
http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/
https://github.com/mileszs/wicked_pdf/issues/48
Small change to the above code to fix issue that prevented CSS from being rendered correctly.
Learn MoreEver wonder how you can write a cucumber test that would test how your web app responds to a different format, something like JSON or XML?
I was trying to do the following:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
Background:
Given I am logged in
And there is the following feeds:
| title | body | category |
| first feed | something good | default |
| second feed | even better | notice |
| 3rd feed | something awesome | notice |
Scenario: Reading feeds via json
When I go to the feeds page using json
And I should see a json file
And I should see 3 feeds in the json |
Running this code I would get a “Can’t find mapping from “the feeds page using json” to a path.”
Trying to figure out how I can do this, I tried to write a new step, like this:
|
1 |
When %r{^I go to the (w+) page using (w+)$} do |page, format|... |
but this resulted in: Ambiguous match of “I go to the feeds page using json”
So, I posted the question on StackOverFlow and it seems everyone was thinking the same way I was.
I continued playing with this idea and here is how I solved the problem:
Modifying the paths.rb file, I changed (Changes are in bold)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
def path_to(page_name)
# Split out format if page_name includes ' using '
# Example: When I go to the accounts page using json
<strong>page_name, format = page_name.split(' using ')</strong>
case page_name
when /the homes?page/
'/'
when /the new account page/
#pass format
new_account_path(<strong>:format => format</strong>)
else
begin
page_name =~ /the (.*) page/
path_components = $1.split(/s+/)
# Also make sure to pass format to the 'guessed' path
self.send(path_components.push('path').join('_').to_sym<strong>, :format => format</strong>)
rescue Object => e
raise "Can't find mapping from "#{page_name}" to a path.n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end |
This way I don’t have to modify anything else in my features and everything just works.
Learn MoreToday I’m thinking of getting back into so good old work and I read there is a new patch to Ruby, version p330. So I figure that RVM (Ruby Version Manager) being so easy and quick to update, I’d do the good old “rvm get head, rvm reload, rvm update 1.8.7″ and I’m off to the races.
Well it wasn’t quite as simple. I ended up with an error:
ruby-1.8.7-p330 - #fetching
ruby-1.8.7-p330 - #extracting ruby-1.8.7-p330 to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #extracted to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #configuring
ruby-1.8.7-p330 - #compiling
Error running 'make ', please read /Users/andrew/.rvm/log/ruby-1.8.7-p330/make.log
There has been an error while running make. Halting the installation.
When I looked into the the make.log, It had this to say:
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)
So, I figured this was going to take too long to deal with, and moved on to working on my projects. That is till I opened up my project and and did a “rvm 1.8.7@rails3″ and it come up with:
warn: ruby ruby-1.8.7-p330 is not installed.
To install do: 'rvm install ruby-1.8.7-p330'
Great! Now I can’t upgrade, and I can’t work with what I have!
Long story short, I figured out that I was missing readline (now I’m sure I’ve installed in a long while ago, but I think I was missing the latest version). Also, rvm install readline resulted in an “Unrecognized command line argument: ‘readline’ ( see: ‘rvm usage’ )”
Turns out RVM updated it’s command to install readline to:
rvm package install readline
Update: (Nov 10, 2011)
If you’re using a newer version of RVM, package has been renamed to pkg, so the command to install readline would be:
rvm pkg install readline
However this didn’t fix my install issue, still got the same error. Luckily I found a post that pointed out that my rvm may not know where readline is (odd, as I used rvm to install readline). Running this command allowed me to install it correctly:
rvm install 1.8.7 -C –with-readline-dir=/Users/andrew/.rvm/usr
[Notice: 'andrew' is my username on my mac, yours might be different]
rvm install 1.8.7 -C --with-readline-dir=$rvm_path/usr
Like always, I’m hoping this helps some people out.
Let me know if you have any issues.
Learn More