I''m developing on Windows and deploying to FreeBSD+lighttpd using Switchtower and I''ve got things generally working. My problem now is that file_column data gets zapped every time I deploy, because Switchtower creates a whole new myapp/public directory with each rev. I looked through the file_column docs and found the :root_path option, which I use in my models as follows: class Foo < ActiveRecord::Base if RAILS_ENV == ''production'' then file_column :image, {:root_path => "/home/www/rails-apps/myapp-externals" } else file_column :image end end This is kludgy and I don''t like hard-coding a path, but this at least gets file_column to store files outside my application''s root. As far as uploading files goes, this is working fine. But url_to_file_column still generates URIs that point to the directory tree under myapp/public so of course my files aren''t available to the browser. How do I gracefully and maintainably fix this? It''s not simply a matter of a redirect in my lighttpd.conf since the url_for_file_column uris have paths that share namespace with controllers. The thought of making an explicit redirect for every file_column-managed field seems un-Rails-like in the extreme. Any thoughts on how to do this in a way that won''t require changes to lighttpd.conf every time I add or change a file_column field in my schema? Thanks. -sk -- Posted via http://www.ruby-forum.com/.
On 1/17/06, Steve Koppelman <hatlessnyc@yahoo.com> wrote:> I''m developing on Windows and deploying to FreeBSD+lighttpd using > Switchtower and I''ve got things generally working. My problem now is > that file_column data gets zapped every time I deploy, because > Switchtower creates a whole new myapp/public directory with each rev. > > I looked through the file_column docs and found the :root_path option, > which I use in my models as follows: > > class Foo < ActiveRecord::Base > if RAILS_ENV == ''production'' then > file_column :image, {:root_path => > "/home/www/rails-apps/myapp-externals" } > else > file_column :image > end > end > > > This is kludgy and I don''t like hard-coding a path, but this at least > gets file_column to store files outside my application''s root. > > As far as uploading files goes, this is working fine. But > url_to_file_column still generates URIs that point to the directory > tree under myapp/public so of course my files aren''t available to the > browser.Looking in the source there is another config option, :web_root. Have you tried using that in conjuction with :root_path? I''m still reading the source to see exactly what it does, there is no doc for it but it is listed as a config option. # default options. You can override these with +file_column+''s +options+ parameter DEFAULT_OPTIONS = { :root_path => File.join(RAILS_ROOT, "public"), :web_root => "", :mime_extensions => MIME_EXTENSIONS, :extensions => EXTENSIONS, :fix_file_extensions => true, :permissions => 0644, # path to the unix "file" executbale for # guessing the content-type of files :file_exec => "file" }.freeze> > How do I gracefully and maintainably fix this? It''s not simply a matter > of a redirect in my lighttpd.conf since the url_for_file_column uris > have paths that share namespace with controllers. The thought of making > an explicit redirect for every file_column-managed field seems > un-Rails-like in the extreme. > > Any thoughts on how to do this in a way that won''t require changes to > lighttpd.conf every time I add or change a file_column field in my > schema? > > Thanks. > > -sk > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jon Smirl jonsmirl@gmail.com
Hi Steve, On 1/18/06, Steve Koppelman <hatlessnyc@yahoo.com> wrote:> I''m developing on Windows and deploying to FreeBSD+lighttpd using > Switchtower and I''ve got things generally working. My problem now is > that file_column data gets zapped every time I deploy, because > Switchtower creates a whole new myapp/public directory with each rev. > > I looked through the file_column docs and found the :root_path option, > which I use in my models as follows: > > class Foo < ActiveRecord::Base > if RAILS_ENV == ''production'' then > file_column :image, {:root_path => > "/home/www/rails-apps/myapp-externals" } > else > file_column :image > end > end > > > This is kludgy and I don''t like hard-coding a path, but this at least > gets file_column to store files outside my application''s root. > > As far as uploading files goes, this is working fine. But > url_to_file_column still generates URIs that point to the directory > tree under myapp/public so of course my files aren''t available to the > browser.As Jon already mentioned, you could use the ":web_root" option. Set it to the relative URL that is needed to reach the path you gave as :root_path. Another possibility is to use a symbolic link that points into your shared directory (same as for public/system). You can even extend your switchtower recipes to automate creation of these links. The switchtower docs will tell you more about how this can be done. As far as I remember, there was a thread on this mailing list as well, that covered, how to integrate file_column with switchtower. Sebastian
Sebastian Kanthak wrote:> As Jon already mentioned, you could use the ":web_root" option. Set it > to the relative URL that is needed to reach the path you gave as > :root_path. Another possibility is to use a symbolic link that points > into your shared directory (same as for public/system). You can even > extend your switchtower recipes to automate creation of these links. > The switchtower docs will tell you more about how this can be done. > > As far as I remember, there was a thread on this mailing list as well, > that covered, how to integrate file_column with switchtower. > > SebastianThanks, guys. I ended up using 1) :root_path on each of my file_column declarations in my models to specify the absolute path to the directory where I want the production server to put file_column files 2) :web_root on each file_column model declaration to assign a URI prefix ("ext/" in this case), and then 3) an alias in my lighttpd.conf pointing requests for the prefix to the absolute path. In order to allow development to continue smoothly on Win32 with a different directory tree, the :web_root and :root_path only get set in the production environment. I suppose it would be better to express the conditionals in the environment files, but it''s working for the moment. I will probably take Sebastian''s suggestion and change things to use a symlink created by switchtower rather than a lighttpd.conf alias directive to allow the server to get to the files outside the docroot. The more that can be handled within rails rather than the webserver, the better. Given the momentum behind Switchtower, I think it would be a good idea to create a standard location for asset directories that maybe get auto-generated alongside an application''s RAILS_ROOT during development, and get generated empty as needed via Switchtower, but are not part of the tree managed by SCM. Not sure how that would work. Or if that''s too complex given different dev and prod evvironments, there should at least be a standard configuration directive for the production environemt that contains an application-wide external asset path instead of sticking things in public/. Nu? -sk -- Posted via http://www.ruby-forum.com/.