Trying to implement HTTP digest authentication in a Rails ApplicationController but am getting an enexpected exception on my call to authenticate_or_request_with_http_digest(REALM):
undefined method `unpack' for nil:NilClass
Top of stacktrace:
/Users/chadmiko/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/base64.rb:58:in
`decode64' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:301:in
`validate_nonce' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:188:in
`validate_digest_response' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:179:in
`authenticate' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:168:in
`authenticate_with_http_digest' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:163:in
`authenticate_or_request_with_http_digest'
Other outputs (note: I'm using rvm and have created a project gemset):
chadmiko [ ~/Documents/Projects/msa-web ]$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
chadmiko [ ~/Documents/Projects/msa-web ]$ rails --version
Rails 3.2.8
Also, if I startup irb:
chadmiko [ ~/Documents/Projects/msa-web ]$ irb
1.9.2-p290 :001 > require 'base64'
=> true
Feel like there's a simple solution here but I'm just missing it. Any tips would be appreciated. Thanks.
Related
Calling "sanitize" method on anything causes a missing method error in Rails 3 with Collective Idea's Money Gem
sanitize "trololo"
=>
undefined method `id2name' for {:instance_writer=>false}:Hash
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:7:in `block in cattr_reader'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:5:in `each'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:5:in `cattr_reader'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:54:in `cattr_accessor'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:48:in `<class:LinkSanitizer>'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:47:in `<module:HTML>'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:5:in `<top (required)>'
actionpack (3.2.8) lib/action_view/helpers/sanitize_helper.rb:174:in `white_list_sanitizer'
actionpack (3.2.8) lib/action_view/helpers/sanitize_helper.rb:60:in `sanitize'
Has anyone experienced this error before?
After digging around in the source code I found this: The money gem defines the cattr_accessor helper methods (see in file YOUR_GEM_DIR/collectiveidea-money-1.7.4/lib/support/cattr_accessor.rb) as does active_support (see in file YOUR_GEM_DIR/activesupport-3.2.8/lib/active_support/core_ext/class/attribute_accessors.rb).
Unfortunately, the implementation in the money gem differs from the one in active_support. And in your case, the money gem has been loaded after active_support and overwrote the *good* active_support implementation.
You can "fix" it by making sure that the money gem is loaded before active_support. If you post more details about your application, I can tell you how to do that...
However, the money gem seems to be pretty outdated, so I suggest you replace it with something that is more recent and actively maintained...
It seems like some people here had this problem but I couldn't find any solution in another topic.
I am doing Chapter 3 of the Ruby on Rails-Tutorial, working on the static pages. When I want to open them on the localhost it gives me a "Routing Error" in the Browser.
My Ruby is currently on version 1.9.3.
My Rails is currently on version 3.2.
I have tried:
restarting the server
saving all the files again
checking any issues in the static_pages_controller.rb
checking any issues in the routes.rb
checking any issues in the static_oages_spec.rb
Also there are no bugs in the HTML code of the single static page. And I can't find any more help in the tutorial, neither in other questions here on StackOverflow.
Edit:
This is the actual error message from the browser:
Routing Error
No route matches [GET] "/static_pages/home" Try running
rake routes for more information on available routes.
if I go to http://localhost:3000/static_pages/home, to one of three static pages I have.
This is routes.rb:
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
end
Also, I tried "rake routes" in the terminal, too. This is the result:
home_static_pages GET /static_pages/home(.:format) static_pages#home
help_static_pages GET /static_pages/help(.:format) static_pages#help
about_static_pages GET /static_pages/about(.:format) static_pages#about
static_pages POST /static_pages(.:format) static_pages#create
new_static_pages GET /static_pages/new(.:format) static_pages#new
edit_static_pages GET /static_pages/edit(.:format) static_pages#edit
GET /static_pages(.:format) static_pages#show
PUT /static_pages(.:format) static_pages#update
DELETE /static_pages(.:format) static_pages#destroy
And this is the error message the server is giving me:
Started GET "/static_pages/home.html" for 127.0.0.1 at 2012-04-03 13:23:54 +0200
ActionController::RoutingError (No route matches [GET] "/static_pages/home.html"):
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Try this :
match "/static_pages/home" => "static_pages#home", :via => :get
match "/static_pages/help" => "static_pages#help", :via => :get
match "/static_pages/about" => "static_pages#about", :via => :get
Add into routes , restart the server and refresh browser .
If you are using Spork you must re-run Spork so your tests will consider the changes in config files like routes.rb, that are pre-loaded with Spork, so are not automatically updated.
Stop Spork (Ctrl + C)
Run Spork again (bundle exec spork)
Source: this is the source of this information
"after changing a file included in the prefork loading (such as routes.rb), you will have to restart the Spork server to load the new Rails environment.
If your tests are failing when you think they should be passing, quit the Spork server with Control-C and restart it
your routes.rb file has problems, use either RESTful style:
resource :static_pages do
collection do
get :home
get :help
get :about
end
end
or the non RESTful style:
match "static_pages/home", :controller => "static_pages", :action => "home"
match "static_pages/help", :controller => "static_pages", :action => "help"
match "static_pages/about", :controller => "static_pages", :action => "about"
for more details please refer to official guide: http://guides.rubyonrails.org/routing.html
I had a few problems working through the Rails Tutorial, and it helped to be able to consult the author's GitHub repo: https://github.com/railstutorial
Find the file you're working on and compare it line by line. Or just cut and paste the full file and see if it will run, then track down your error.
If you check the routes.rb in config you'll probably find that the there is a 'e' missing from /home. Add that and you are golden. Or green. Or whatever :)
check your http:// address, specifically if you are on localhost:3000/path or localhost:3000/path1/path2, etc
Once you change the format of your mapping from get to match you will not need static_pages anymore, just go straight to localhost:3000/pagename e.g localhost:3000/about
From Ruby 2 to Ruby 3 there are some differences, but still the documentation for 3 is not easy to be found. There should be a tutorial only for that: practical differences between rails 2 and 3.
The guide provided by downloading Ruby on rails is "The book of ruby" but it's not good anymore. It should at least contain an advice at the beginning of chapter 19.
In
config/routes.rb
uncomment
root :to => 'welcome#index'
After upgrade to Rails 3.0.10 I'm getting strange error if I set config.cache_classes=true
NoMethodError (undefined method increment_counter' for ActiveRecord::Relation:Class):
activerecord (3.0.10) lib/active_record/associations.rb:1553:inbelongs_to_counter_cache_after_create_for_form'
activesupport (3.0.10) lib/active_support/callbacks.rb:424:in _run_create_callbacks'
activerecord (3.0.10) lib/active_record/callbacks.rb:277:increate'
activerecord (3.0.10) lib/active_record/persistence.rb:257:in create_or_update'
activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update'
activesupport (3.0.10) lib/active_support/callbacks.rb:444:in _run_save_callbacks'
activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update'
activerecord (3.0.10) lib/active_record/persistence.rb:60:in save!'
activerecord (3.0.10) lib/active_record/validations.rb:49:insave!'
activerecord (3.0.10) lib/active_record/attribute_methods/dirty.rb:30:in `save!'
...
I'm saving Answer model which has belongs_to relation with counter cache:
belongs_to :form, :counter_cache => true
Strangest thing is that after server restart first save works fine and after that I start getting such exceptions.
Maybe someone could advise where I could start digging for a cause?
The problem was caused by outdated acts_as_taggable_on_steroids gem which was causing class cache issues with Rails3. Switched to acts-as-taggable-on gem - problem solved.
I keep getting the following error when sending a simple e-mail via ActionMailer in Rails:
NoMethodError: undefined method `encode!' for "Hello":String
This is triggered whenever the following is run:
def hello_world_email()
mail( :from => "me",
:to => "you,
:subject => "Hello World"
)
end
From researching this, it looks like it's caused by the differences between Ruby 1.8.7 and 1.9.*, which has built-in character encoding support.
Is there any way of getting ActionMailer to work with Ruby 1.8.7 and avoid this issue? (I can upgrade Ruby on my machine, but I can't do the same for everyone else working on the project). Given that the whole of Rails 3.0.9 (of which ActionMailer is a part) is meant to work with Ruby 1.8.7, I keep thinking that there must be a way...
Note: My exact version of Ruby is ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] (pre-installed on OSX).
You may have an issue with using Ruby 1.8 and having a constant Encoding defined by a gem.
For example we found an issue with a class that was including REXML at a global scope.
The line in question in the library was:
value.encode!(charset) if defined?(Encoding) && charset
This is checking for a global constant called Encoding. (Which could be defined in any gem at global scope.) Our problem was actually the include which then made REXML::Encoding available everywhere as Encoding. You could try grepping or acking your codebase for "module Encoding" or "class Encoding".
Hope this helps.
The stack trace below defines the problem.
NoMethodError: undefined method `encode!' for "Generate":String
mail (2.2.19) lib/mail/fields/unstructured_field.rb:169:in `encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:138:in `fold'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:108:in `wrapped_value'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:70:in `do_encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:52:in `encoded'
mail (2.2.19) lib/mail/field.rb:123:in `send'
mail (2.2.19) lib/mail/field.rb:123:in `method_missing'
mail (2.2.19) lib/mail/header.rb:190:in `encoded'
mail (2.2.19) lib/mail/header.rb:189:in `each'
mail (2.2.19) lib/mail/header.rb:189:in `encoded'
mail (2.2.19) lib/mail/message.rb:1708:in `encoded'
actionmailer (3.0.10) lib/action_mailer/base.rb:445:in `set_payload_for_mail'
actionmailer (3.0.10) lib/action_mailer/base.rb:425:in `deliver_mail'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.10) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
actionmailer (3.0.10) lib/action_mailer/base.rb:424:in `deliver_mail'
mail (2.2.19) lib/mail/message.rb:230:in `deliver'
I had the same error, when trying to test my devise confirmation emails. Weird thing was, running the test isolated did not throw this exception. Running the whole stack did. After doing a binary search, i found, that one of my specs used REXML to parse some content.
require 'spec_helper'
require 'rexml/document'
include REXML
doc = Document.new(response.body)
I dont't know, why i included REXML, presumably, because i wanted to save the REXML:: in front of Document. But changing the code to this fixed the problem:
require 'spec_helper'
require 'rexml/document'
doc = REXML::Document.new(response.body)
if you happen to use code like this somewhere, this may fix this encode! issue with ruby 1.8.7
I found the issue to be with the mailer gem, changing to 2.2.13 fixed it for me.
In my rails 2.3.8 app running in windows 7, getting the following error when attempting to start the server:
D:\app1>ruby script/server
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- active_support/core_ext (LoadError)
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from D:/app1/vendor/rails/activesupport/lib/active_support.rb:56
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from D:/app1/vendor/rails/railties/lib/commands/server.rb:1
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
In the custom require file block below... line 36 is "gem_original_require path"
def require(path) # :doc:
gem_original_require path
rescue LoadError => load_error
if load_error.message =~ /#{Regexp.escape path}\z/ and
spec = Gem.searcher.find(path) then
Gem.activate(spec.name, "= #{spec.version}")
gem_original_require path
else
raise load_error
end
end
gem list as follows:
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
builder (3.0.0)
calendar_date_select (1.16.1)
cgi_multipart_eof_fix (2.5.0)
gem_plugin (0.2.3)
google4r-checkout (1.0.6.1)
i18n (0.5.0)
liquid (2.2.2)
money (3.5.5)
mongrel (1.1.5 x86-mingw32)
mysql (2.8.1 x86-mingw32)
rack (1.1.0)
rails (2.3.8)
rake (0.8.7)
rmagick (2.12.0 mswin32)
Looked around with portions of the error, but I'm not quite sure where to start.
Just looking at the stack trace ... it looks like your application is on drive "D" and the ruby files are on drive "C".
Maybe when its performing the require
filenames = Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.map do |path|
File.basename(path, '.rb')
end
its requiring that path on "D" when it should be on "C". That's my best guess. Good luck.
create a file name
core_ext.rb
in the
C:\Ruby\lib\ruby\gems\1.8\gems\activesupport-2.3.8\lib\active_support
and edit add the content to the following lines
filenames = Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.map do |path|
File.basename(path, '.rb')
end
# deprecated
filenames -= %w(blank)
filenames.each { |filename| require "active_support/core_ext/#{filename}" }