FaceboxRender: Use lightbox seamlessly in Rails
FaceboxRender is a Rails Ajax UI plugin let you use lightbox seamlessly. It’s depend on Facebox Javascript library. You must install jQuery and Facebox first:
- Download jQuery (Suggest that you can install jRails to replace Prototype library totally)
- Download facebox
- Copy facebox js file to /public/javascripts/
- Copy facebox css file to /public/styleshees/
- Copy facebox all image files to /public/facebox/
- Config layout’s stylesheet_link_tag and javascript_include_tag to add these js,css files
FaceboxRender is hosted at github. Please download tarball and put in your vendor/plugins/facebox_render/
Then add these code at your controller, or just put it in /app/controllers/application.rb
include FaceboxRender
Return to Rails view code, when want to call a lightbox:
facebox_link_to "Login", :url => login_url
Or you can use remote_link_to, remote_form_tag Ajax Helper. The difference is that facebox_link_to will show a Loading lightbox first, send Ajax request second.
The magic is the action:
def new
# do some thing you want
respond_to do |format|
format.html
format.js { render_to_facebox }
end
end
We use respond_to to handle ajax request, and by defaut render_facebox will render HTML version without layout (i.e. new.html.erb). Of course we also support passing :action, :template, :partial, :html parameter happily
Passing :msg will insert <div class=”message”>your msg</div>, it’s convenient to do some notice or warning messages.
Beside render_facebox, we have close_facebox and redirect_from_lightbox.
So, you can use remote link or remote form submit to call facebox. More, in facebox you can use remote link or remote form submit again. the action can update lightbox using render_facebox or close lightbox using close_facebox or reload page using redirect_from_facebox.
Please see FaceboxRender’s README .
P.S. This post have Chinese version at ihower’s blog.
About this entry
You’re currently reading “FaceboxRender: Use lightbox seamlessly in Rails,” an entry on Handlino
- Author:
- ihower
- Published:
- February 26th, 2008 / 11am
- Category:
- Rails, Registrano
12 Comments
Jump to comment form | comments rss [?] | trackback uri [?]