Oct 08

I found interesting pluginn for lightbox implementation with Facebook style, named Facebox. It allows us to use lightbox seamlessly in a Rails application.  You would use make a lightbox to display notice or error messages, form or even image without having to reload a page.

Installation:

  1. Install FaceboxRender from here http://github.com/ihower/facebox_render/
  2. Download jQuery
  3. Download facebox at http://famspam.com/facebox
  4. Copy facebox js file to /public/javascripts/
  5. Copy facebox css file to /public/styleshees/
  6. Copy facebox all image files to /public/facebox/
  7. Update your layout’s stylesheet_link_tag and javascript_include_tag to add these js,css files

Usage:

Add this in your application_controller.rb :

include FaceboxRender

In view code, when you want to call a lightbox :

facebox_link_to "Login", :url => login_url   

This is an example on how the code in a controller:

def new
  # do some thing you want
  respond_to do |format|
    format.html
    format.js { render_to_facebox }
  end
end

That’s it!. You just need to make a html.erb page as usual and call that page as a lightbox. It also support passing :action, :partial, :template, and :html parameter.
Isn’t that easy?

Leave a Reply

Security Code: