This project is archived and is in readonly mode.
missing config.gem causes a strange error in rake tasks
Reported by Akira Matsuda | February 19th, 2009 @ 08:36 PM
Since commit f716ab92bf4872db635903f7b57f1c0d025e40a4 which refers to #802 , all rake tasks lacks the ability to tell us missing gems error.
For example, when you add a config.gem like this,
config.gem 'no-such-gem' # doesn't really exist!
any rake task fails without telling us the real reason of failure but with a very weird error message like the following.
% rake routes
rake aborted!
A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb
I believe that check_gem_dependencies should be run inside the initializer with raising error. Is there any good idea to solve both #802 and this problem?
Comments and changes to this ticket
-
Markús February 20th, 2009 @ 11:28 AM
I'm getting the same error in a fresh rails application using rails-edge. In this case I'm not declared anything, I created it and I ran script/generate (with any argument, all return the same), an then...
rails/actionpack/lib/action_controller/session/cookie_store.rb:163:in `ensure_session_key': A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb (ArgumentError) from /Users/marcosariaspena/code/tests/test/vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:74:in `initialize' from /Users/marcosariaspena/code/tests/test/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:72:in `new'
The environment apparently ignores session = {} declaration, both in initializer/session_store.rb or in environment.rb.
Some rake tasks returns this error too (such as "rake middleware")
-
Markús February 20th, 2009 @ 12:41 PM
- Assigned user set to josh
I've found something about this error:
This commit changes the way SessionStore is initialized, allowing custom settings in session store...
Well, the actual code is:
# actionpack/lib/action_controller/middlewares.rb - line 7 use lambda { ActionController::Base.session_store }, ActionController::Base.session_options
This, for some reason, it's not interpreted as expected and doesn't load ActionController::Base.sesion_store, whatever value it has, you must add :if => true at the end to force that load
# actionpack/lib/action_controller/middlewares.rb - line 7 use lambda { ActionController::Base.session_store }, ActionController::Base.session_options, :if => true
I'm trying to figure out in my local rails clone why is this happening
-
Markús February 20th, 2009 @ 02:06 PM
I've found another strange thing regarding this error
If you change this code
# actionpack/lib/action_controller/middleware_stack.rb - line 17 options = args.extract_options! if options.has_key?(:if) @conditional = options.delete(:if) else @conditional = true end args << options unless options.empty?
For this one, which is practically the same (I'm going to annotate the differences), all works fine
# options = args.extract_options! always do a pop in args if args.last.is_a?(Hash) && args.last.has_key?(:if) @conditional = args.last.delete(:if) # only do a pop if the args.last remains empty after deleting the :if option args.pop if args.last.empty? else @conditional = true end # args << options unless options.empty? should retrieve the extracted options without the if, but this don't work, only if the pop is made when the args.last is an empty hash
As you can see, this 2 pieces of code are practically the same, but produces 2 different results. I think the eval() of actionpack/lib/action_controller/middlewares.rb file might be related with this behavior.
-
josh February 20th, 2009 @ 04:56 PM
- State changed from new to duplicate
- Milestone cleared.
-
Markús February 20th, 2009 @ 07:23 PM
I don't think the whole ticket it's a duplicate, the error pointed by Akira Matsuda its still there.
I've updated my rails repo with the middleware fix by Sven Fuchs, and a fresh app works fine, but once you specify a config.gem which you have not installed yet, the error raise again
Rails::Initializer.run do |config| config.gem "aws-s3", :lib => "aws/s3" # Or any gem you had't installed yet # .. end
"rake gems" fails with this message:
rake aborted! A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>