My friends often asked me how to upload file using AJAX, and usually they got answer “in no way”. Correct answer, but what if I need to upload file without full page reloading? And, of course, I want to use RJS in this case. Here I’ll explain what to do to get effect very similar to AJAX file upload (btw, Gmail uses this technique).
Flexible application configuration in Ruby on Rails
(19,121 views) In my current project in Ruby on Rails I need to store application specific configuration. There are several approaches I’ve found: AppConfig plugin, several methods described on HowtoAddYourOwnConfigInfo wiki page, but neither one looks “config-like”. Me with my friend, Alexey Kovyrin, discovered all of them and decided to use YAML-file. Ideal configuration, I think, file looks like following:
1 2 3 4 5 6 7 8 9 10 11 | span class="re0"> common: support_email: admin@myhost.com root_url: myhost.com photos_max_number: 6 production: email_exceptions: true development: root_url: localhost:3000 photos_max_number: 10 |
In this example you can see three sections: common will be used as base configuration for all environments, production and development - environment specific options. Possible sections are production, development, and testing, or any other custom environment name. I’ve placed this file in config/config.yml and added following code to config/environment.rb:
1 2 3 4 5 6 7 | require 'ostruct' require 'yaml' config = OpenStruct.new(YAML.load_file("#{RAILS_ROOT}/config/config.yml")) env_config = config.send(RAILS_ENV) config.common.update(env_config) unless env_config.nil? ::AppConfig = OpenStruct.new(config.common) |
Now I’m able to use constructions like AppConfig.support_email and AppConfig.root_url. Looks like I’ve kept all my configs as DRY as possible :-)
Upgrading Apache to version 2.2 in Debian
Great news, guys! Apache 2.2 is in unstable now. I was very discouraged when tried to do apt-get install apache2-utils and it proposed me to remove apache2 and install it again :-) I decided to install new version to test rails with Apache 2.2, mod_proxy_balancing and mongrel. In this post I’ve described my adventures (or misfortunes?)
validates_uniqueness_of and MySQL unique index
(11,451 views) Yesterday in mailing list of russian RoR group we have discussed following problem. MySQL database has unique index and model has validates_uniqueness_of constraint. Do we need to handle MySQL server exceptions or RoR’s validation will be enough?
Encoding media files in Ruby using ffmpeg/mencoder with progress tracking
(38,537 views) In my current project I need to encode media files from any format to several predefined. Furthermore I need to track progress and show it for the customer. I don’t want to describe wich media formats I need and what troubles with converting (maybe it will be my future posts, if anybody interested), instead I will describe common idea how to implement encoder scripts and how to track progress.
English