RailsDAV update, dynamic base_dir
January 13th, 2007
I’ve added a couple of features to the RailsDAV act_as_filewebdav. Dynamic base directories and absolute base directories.
act_as_filewebdav takes two parameters:
base_dir can take either a String for the base directory or a Symbol which will use a method in the controller to return the base directory to use on each request.
absolute allows for either true or false (defaults to false) to determine to use either an absolute filesystem directory or relative to the RAILS_ROOT
So a common example usecase to allow users to upload/download to their own directories after they have logged on using basic HTTP authentication.
class FileDavController < ApplicationController
act_as_filewebdav :base_dir => :user_web_dir, :absolute => true
before_filter :user_auth
def user_auth
basic_auth_required {|username, password| session[:user] = User.authenticate(username,password) }
end
def user_web_dir
"/var/user/#{session[:user].username}"
end
end
11 comments »
New WebDAV Ruby On Rails Plugin Release
January 6th, 2007
I’ve finally had some time over the holidays to put together a new release of the RailsDAV plugin for WebDAV functionality in Rails.
It’s still really a 0.0.2 release as bugs are to be fixed and still havn’t nailed a structure for the plugin i’m happy with. But for now I have improved the structure and implemented some fixes courtesy of Albert Ramstedt. Thanks Albert.
As such the use of RailsDAV plugin has changed a bit and it won’t be backwards compatible so scan the code if you are using it.
The act_as_railsdav method is attached to ActionController and can be used by calling act_as_railsdav on a controller
class MyDavController < ActionController::Base
act_as_railsdav
The controller must then have a route of
map.connect 'mydav/*path_info', :controller => 'my_dav', :action => 'webdav'
It is then necessary to implement some or all of the following methods:
- mkcol_for_path(path)
- write_content_to_path(path, content),
- copy_to_path(resource, dest_path, depth)
- move_to_path(resource, dest_path, depth)
- get_resource_for_path(path)
get_resource_for_path needs to return a WebDAVResource object such as FileWebDavResource
To add webdav authentication to your controller just use
class MyDavController < ActionController::Base
act_as_railsdav
before_filter :my_auth
def my_auth()
basic_auth_required |username, password| do
session[:user] = User.your_authentication(username,password)
end
end
Additionally you can add a simple filesystem expose to a controller by:
class FileDavController < ActionController::Base
act_as_filewebdav :base_dir => 'public'
end
The new version of the plugin can be donwloaded using
svn co http://svn.liverail.net/svn/plugins/railsdav
It also requires the following gems
- unicode (gem install unicode)
- mimetypes (gem install mime-types)
I’m going to spend a lot more time on RailsDAV now so let me know what you want out of it!
25 comments »