Adding a before_filter to static content

Hi,

I have a Rails site that uses a before_filter in the application
controller that does some authentication and authorization work.

I also have a bunch of HTML in folders in the application’s public
directory.

Before a user can view anything in the public directory, I’d like to
authenticate them. How could I do that?

I’m using mongrel, if it matters.

Thanks,
Joe

On Wed, 2006-06-28 at 19:24 -0700, Joe Van D. wrote:

I’m using mongrel, if it matters.
You could probably cook up a little Mongrel filter to do this if you
were feeling adventurous. Go check out the source to
lib/mongrel/handlers.rb for examples, and read the RDoc on the mongrel
documentation site. Feel free to e-mail me off list if you hit
problems.


Zed A. Shaw


http://mongrel.rubyforge.org/
http://www.railsmachine.com/ – Need Mongrel support?

On 6/28/06, Zed S. [email protected] wrote:

I’m using mongrel, if it matters.

You could probably cook up a little Mongrel filter to do this if you
were feeling adventurous. Go check out the source to
lib/mongrel/handlers.rb for examples, and read the RDoc on the mongrel
documentation site. Feel free to e-mail me off list if you hit
problems.

Thanks – I’ll check it out. Should it be straightforward?

Joe

On 6/28/06, Joe Van D. [email protected] wrote:

I’m using mongrel, if it matters.
Hm…

Say my public directory looks like:

/public
/docs
index.html
page_1.html

What if I create a Rails controller named docs. It would have one
action, that would check to see if the requested file existed. If it
did, then it would render the requested file that’s in the public/docs
directory.

Does that make sense? Anyone think it’ll work?

Joe

On Wed, 2006-06-28 at 20:04 -0700, Joe Van D. wrote:

On 6/28/06, Zed S. [email protected] wrote:

On Wed, 2006-06-28 at 19:24 -0700, Joe Van D. wrote:

You could probably cook up a little Mongrel filter to do this if you
were feeling adventurous. Go check out the source to
lib/mongrel/handlers.rb for examples, and read the RDoc on the mongrel
documentation site. Feel free to e-mail me off list if you hit
problems.

Thanks – I’ll check it out. Should it be straightforward?

Yes, but not easy like Rails. I’m thinking maybe 2 hours work if you
want to hook up basic auth. More if you get fancy and need database
access and such, but you could probably poach that from rails.


Zed A. Shaw


http://mongrel.rubyforge.org/
http://www.railsmachine.com/ – Need Mongrel support?

On 6/28/06, Senthil N. [email protected] wrote:

  page_1.html

It does not make any sense to add authentication for public folders

maybe I would suggest keep your html out of public and when a url is
called, fetch your file and send, it would be through some controller,
where you can have your before_filter or something.

Yeah, that would probably be best. I’ll try it.

Joe Van D. wrote:

On 6/28/06, Joe Van D. [email protected] wrote:

I’m using mongrel, if it matters.
Hm…

Say my public directory looks like:

/public
/docs
index.html
page_1.html

What if I create a Rails controller named docs. It would have one
action, that would check to see if the requested file existed. If it
did, then it would render the requested file that’s in the public/docs
directory.

Does that make sense? Anyone think it’ll work?

Joe

It does not make any sense to add authentication for public folders

maybe I would suggest keep your html out of public and when a url is
called, fetch your file and send, it would be through some controller,
where you can have your before_filter or something.

regards
A.Senthil N.
http://senthilnayagam.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs