Ajax Tree Plugin

Posted by anup.narkhede on December 19, 2007

Introduction

This is a helper plugin to generate ajax based tree structure (two level). It can be used for two models having n:m or 1:n relationships. A leaf from any branch can be dragged and dropped in another branch. A scaffolding arrangement is also done to create a new branch, add leaf etc.

Sceenshot

For example:

Installation:

Here we take the previous example of Category and Article models. Generate the ajax controller for the two models.

Usage

Example

Copy static files

Copy add.png, delete.png from /vendor/plugins/ajax_tree/ directory to /public/images directory.

Copy ajax_tree.css file from /vendor/plugins/ajax_tree/ directory to /public/stylesheets/ directory.
Include css in your application layout

Call the helpers

Specify model names for branch model and leaf model in /views/home/_show_ajax_tree.rhtml partial.

Then, call this partial in any rhtml, where you want to display the ajax tree. In this case, we have done it in /views/home/index.rhtml

home_controller.rb (Generated automatically)

index.rhtml

Contributions:

This project is hosted at http://code.google.com/p/ajax-tree/. Please leave your feedback.

Flash Movie embed code (RubyOnRails)

Posted by anup.narkhede on December 15, 2007

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.