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 `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 |
Today 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 MoreI spent a few good hours trying to figure out how to strip a coloured ruby string:

which comes out as this:
>> p t
"2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"
=> nil
Now I tried to gsub the string and remove the colour using a RegEx like this:
> t.gsub(/\e[(d+)m/, "")
=> "2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"
But as you can see, nothing changed. After reading a whole lot of docs on Ruby, Googling around and reading the Ruby String class I came to this conclusion:
>> b = "e[33m"
=> "e[33m"
>> b.each_byte{|c| puts c}
27
91
51
51
109
=> "e[33m"
>> "" << 27 #The only way I know how to add ASCII codes to string
=> "e"
Now what this allowed me to do is figured out the ASCII code for the e character. However because normally you escape the back slash on regular expressions, once I figured out e was a valid character, I got this:
>> "e[33m".gsub(/e[(d+)m/, '')
=> ""
I hope this saves someone a few hours!
Learn MoreLast night I was trying really hard to get MongoMapper to work with Paperclip via GridFS and failed. It seems right now Paperclip or even CarrierWave are not ready to be used with the latest MongoMapper drivers and GridFS (and I needed to use the latest drivers due to Scopify).
After giving up using GridFS, I wanted to use Paperclip with MongoMapper with the normal file system and I found this article from Ben Curtis, however with the latest version of Paperclip (version 2.3.1.1) and MongoMapper (version 0.7.6) I was unsuccessful, kept getting:
Anonymous modules have no name to be referenced by
After reading the backtrace and diving into the paperclip source code I noticed that it was trying to use the ActiveRecord.logger and since I’ve removed ActiveRecord from my app, it was failing (with the odd error).
After some tweaking of Ben’s code, I came up with this: http://gist.github.com/424158
Learn MoreToday I’ve upgraded my gems and noticed that when running my autospec I get an odd error:
[01:09:25 /usr/local/lib/ruby/gems/1.8/gems/ruby-ole-1.2.10/lib/ole/storage/base.rb:146:load]
WARN root name was “R”
sh: line 1: 6303 Trace/BPT trap /usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.1.2/fsevent/darwin/fsevent_sleep ‘/Users/andrew/rails_apps/example_com’ 2>&1sh: line 1: 6307 Trace/BPT trap /usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.1.2/fsevent/darwin/fsevent_sleep ‘/Users/andrew/rails_apps/example_com’ 2>&1
sudo gem uninstall autotest-fsevent‘) and install the older version (‘sudo gem install autotest-fsevent --version 0.1.1‘)/usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.2.1/fsevent/darwin/fsevent_sleep ; exit;
~% /usr/local/lib/ruby/gems/1.8/gems/autotest-fsevent-0.2.1/fsevent/darwin/fsevent_sleep ; exit;
dyld: unknown required load command 0x80000022
zsh: trace trap
The only work around (outside of downgrading to version 0.1.1) is to copy fsevent_sleep from version 0.1.1 to version 0.2.1. However I’m not sure how stable that solution is.
Learn MoreIn Rails 2.3, templates are simple ruby files containing DSL for adding plugins, gems, initializers, etc. to your freshly created Rails project. To apply the template, you need to provide the rails generator with location of the template you wish to apply, using -m option.
Reading up on the commands in the template system and watching the railscasts.com episode, I got fired up on the possibilities of such a simple yet amazing system. So I dove in and started creating my base template. I was so excited that I write the whole template out in one go and than ran it. The result: FAIL!
After including some gems, I ran a rake "gems:install" and ended up with an Exec format error. I googled the problem and found that mostly Windows users were getting this error and the recommend solution was to use a rake.bat (or rake.cmd) instead of the rake command from ruby. So I wrote my own function:
#HELPERS
def win_env?
RUBY_PLATFORM=~ /win32/
end
def rake(command, options = {})
env = options[:env] || 'development'
log 'rake', "#{command} in #{env} "
sudo = win_env? ? '' : (options[:sudo] ? 'sudo' : '')
rake_cmd = win_env? ? "rake.bat" : 'rake'
in_root { run("#{sudo} #{rake_cmd} #{command} RAILS_ENV=#{env}", false) }
end
Another thing that I was able to fix is the “Sudo” option, works great on UNIX systems but not so great in Windows. I haven’t been able to test it but I’m pretty sure this will work on a UNIX system without any issues.
All worked out great till I ran run "cucumber features -n" and got the exact same error! Lucky there was a .bat version of cucmber command so I was able to easily fix it by calling run "cucumber#{win_env? ? '.bat': ''} features -n"
One more small issue I found in Windows when making a template was in the git command. When doing a commit you need to use double quotes inside the commit message otherwise you get an error: pathspec 'commit'' did not match any file(s) known to git.
If you’re interested in downloading my template, you can download it from here
If you really want to see the power of template system I recommend you read the template_runner.rb in the rails folder. Enjoy and have fun with it!
Learn More