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 Dyk wrote:> 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.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://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
On 6/28/06, Zed Shaw <zedshaw@zedshaw.com> wrote:> On Wed, 2006-06-28 at 19:24 -0700, Joe Van Dyk wrote: > > 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. > > 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 Wed, 2006-06-28 at 20:04 -0700, Joe Van Dyk wrote:> On 6/28/06, Zed Shaw <zedshaw@zedshaw.com> wrote: > > On Wed, 2006-06-28 at 19:24 -0700, Joe Van Dyk 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://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
On 6/28/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> 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.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
Senthil Nayagam
2006-Jun-29 05:58 UTC
[Rails] Re: adding a before_filter to static content
Joe Van Dyk wrote:> On 6/28/06, Joe Van Dyk <joevandyk@gmail.com> 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? > > JoeIt 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 Nayagam http://senthilnayagam.com -- Posted via http://www.ruby-forum.com/.
On 6/28/06, Senthil Nayagam <senthil@senthilnayagam.com> wrote:> Joe Van Dyk wrote: > > On 6/28/06, Joe Van Dyk <joevandyk@gmail.com> 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.Yeah, that would probably be best. I''ll try it.