# How do I update middleware for Rails 3?

**URL:** <https://www.ruby-forum.com/t/how-do-i-update-middleware-for-rails-3/186501>\
**Category:** Rails\
**Created:** [April 8, 2010, 2:30am UTC](https://www.ruby-forum.com/t/how-do-i-update-middleware-for-rails-3/186501 "2010-04-08T02:30:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bazzel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@bazzel](https://www.ruby-forum.com/u/bazzel)\
**Post date:** [April 8, 2010, 2:30am UTC](https://www.ruby-forum.com/t/how-do-i-update-middleware-for-rails-3/186501/1 "2010-04-08T02:30:54Z")

</div>

Hello,

I’m updating an application to Rails 3 that has Uploadify implemented as  
described by John Nunemaker here:  
[http://railstips.org/blog/archives/2009/07/21/uploadify-and-rails23/](http://railstips.org/blog/archives/2009/07/21/uploadify-and-rails23/)

My questions are:

1. Where should middleware live in a Rails 3 application?  
app/middleware?

2. Is the middleware path loaded in config/application.rb? Or is there a  
way to do it in config/environment.rb?

3. What should I update the following code to to make it work in Rails  
3?

# config/initializers/session\_store.rb

ActionController::Dispatcher.middleware.insert\_before(  
ActionController::Session::CookieStore,  
FlashSessionCookieMiddleware,  
ActionController::Base.session\_options[:key]  
)

Specifically, how do I call each of the following:

- ActionController::Dispatcher.middleware.insert\_before
- ActionController::Session::CookieStore
- ActionController::Base.session\_options[:key]

I’ve looked through the Rails 3 source, and tried various combinations  
e.g., ActionDispatch::Cookies, ActionDispatch::Middleware::Cookies,  
ActionController.cookies, etc., but to no avail.

Thanks, Patrick

---

<div class="post-metadata">

**Author:** ![bazzel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@bazzel](https://www.ruby-forum.com/u/bazzel)\
**Post date:** [August 28, 2010, 1:46pm UTC](https://www.ruby-forum.com/t/how-do-i-update-middleware-for-rails-3/186501/2 "2010-08-28T13:46:07Z")

</div>

hi, Patrick.  
Try the following code, it works for me.

replace

# config/initializers/session\_store.rb

ActionController::Dispatcher.middleware.insert\_before(  
ActionController::Session::CookieStore,  
FlashSessionCookieMiddleware,  
ActionController::Base.session\_options[:key]  
)

with

Rails.application.config.middleware.insert\_before(Rails.application.config.session\_store,  
FlashSessionCookieMiddleware,  
Rails.application.config.session\_options[:key])
