Flash Movie embed code (RubyOnRails)
Last week I was working on a code to make my video files embedding (flv) available for external webpages. There are many ways to implement this and I have documented a simple way to achieve it.
I am using a Video model with file_column plugin to store the flv file. The path of stored flv files is /public/video/file_path/[id]/[filename.flv] in my application. I am using ffmpeg to convert files to flv format but I am not including this module here.
Here is the controller to access the video files from server filesystem.
To make this url http://server.com/video/index/[id] to something DRY like http://server.com/v/[id], add this mapping to your routes.rb file.
map.connect ‘v/:id’, :controller => ‘video’, :action => ’show’
The Video model with embed_code method looks as follows:
Finally, @video.embed_code gives the code to embed a video as a swf object in external html page.
yaml_form_builder
This plugin provides a simple way to generate dynamic forms in view. The forms are configured with the help of a yaml configuration file.
1) Installation
2) Configuration
The example below demonstrates a form generated for the following schema.
3) Configuration
Create a file named formconfig.yml in /config directory.
4) Controller
Fetch records in the controller.
5) Finally the helper in View
(views/form/index.rhtml)
The url /form/index shows a form, generated dynamically with the help of above yml configuration file.
Client for Yahoo! Search webservices in RubyOnRails
Here is a client for Yahoo search api using the simplest web service architecture REST (Representational State Transfer).
Working demo: http://demo.anup.info/search
The client application works as:
To begin with, get an application ID from http://developer.yahoo.com.
Controller: search_controller.rb
View: index.rhtml
Partial view: _results.rhtml
Partial View: _error.rhtml
Prototype Window Login Form with Ajax/RJS
Here is a simple tutorial to demonstrate the use of prototype Window login form with RubyOnRails and Ajax. The idea behind this is to override Ok event of Dialog.confirm() form and send Ajax request to controller. The demo application makes use of RJS for Ajax callbacks.
To begin with, download prototype windows library, copy javascripts in your public/javascripts folder and themes to stylesheets folder.
Include the javascripts and stylesheets in layout header.Look at our application.rhtml layout for complete details.
Dynamic Subdomains with RubyOnRails
Following is a step by step guide to configure an application for dynamic subdomains. We are trying to set up wildcard subdomain feature similar to the one done by blogspot.com and wordpress.com.
Step 1
In advanced DNS settings of your domain, add an A record as follows
*.domain.com IN A ***.***.***.*** (server IP address)
Step 2
Modify http.conf to set up a serveralias *.domain.com for http://www.domain.com/.
Make sure you have access, or ask your service provider to do this.
Step 3
Add a wildcard entry for your domain in the Zone file for http://www.domain.com/, so that nonexistant subdomains are resolved to same public_html folder.
Now to check this, keep an index.html file in the public_html folder.
Try browsing http://www.domain.com/ and http://anything.domain.com/ . Both should resolve to the same index.html file. If this succeeds, your dynamic subdomains are set up.
To catch the subdomain in RubyOnRails modify application.rb as follows,
Now you have a subdomain catched by your application controller which can be used in all controllers.
For example, MyController makes use of @subdomain and decides what action to take. (it is a simple redirect action in this case)


