Posted in Knowledge
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:
- Install FaceboxRender from here http://github.com/ihower/facebox_render/
- Download jQuery
- Download facebox at http://famspam.com/facebox
- Copy facebox js file to /public/javascripts/
- Copy facebox css file to /public/styleshees/
- Copy facebox all image files to /public/facebox/
- 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?