Permalink
Browse files

Rails 3 compatibility

  • Loading branch information...
ihower committed May 28, 2010
1 parent 121c19d commit 637dfce7c5cdb094b1abf692218c28b0e17781ed
Showing with 25 additions and 11 deletions.
  1. +7 −4 README.rdoc
  2. +18 −7 lib/facebox_render.rb
View
@@ -4,14 +4,17 @@ FaceboxRender improved plugin let you use lightbox seamlessly using Facebox libr
= Install
- script/plugin install git://github.com/ihower/facebox_render.git
+* script/plugin install git://github.com/ihower/facebox_render.git (for Rails 2)
+* rails plugin install git://github.com/ihower/facebox_render.git (for Rails 3)
= USAGE
== Helper
-
-We have facebox_link_to helper (it's will launch loading facebox first, send ajax request second)
-or you can use link_to_remote, form_remote_tag...etc Ajax helper.
+
+* facebox_link_to helper, it's will launch loading facebox first, send ajax request second)
+* link_to_remote, form_remote_tag ...etc Ajax helper. (for Rails 2)
+* link_to :remote => true, form_for :remote => true ...etc Ajax helper (for Rails 3)
+
Don't use <a href="somelink" ref="facebox">
== Controller
View
@@ -2,16 +2,27 @@ module FaceboxRender
def render_to_facebox( options = {} )
l = options.delete(:layout) { false }
- options[:template] = "#{default_template_name}" if options.empty?
- action_string = render_to_string(:action => options[:action], :layout => l) if options[:action]
- template_string = render_to_string(:template => options[:template], :layout => l) if options[:template]
+ if options[:action]
+ s = render_to_string(:action => options[:action], :layout => l)
+ elsif options[:template]
+ s = render_to_string(:template => options[:template], :layout => l)
+ elsif !options[:partial] && !options[:html]
+ s = render_to_string(:layout => l)
+ end
render :update do |page|
- page << "jQuery.facebox(#{action_string.to_json})" if options[:action]
- page << "jQuery.facebox(#{template_string.to_json})" if options[:template]
- page << "jQuery.facebox(#{(render :partial => options[:partial]).to_json})" if options[:partial]
- page << "jQuery.facebox(#{options[:html].to_json})" if options[:html]
+ if options[:action]
+ page << "jQuery.facebox(#{s.to_json})"
+ elsif options[:template]
+ page << "jQuery.facebox(#{s.to_json})"
+ elsif options[:partial]
+ page << "jQuery.facebox(#{(render :partial => options[:partial]).to_json})"
+ elsif options[:html]
+ page << "jQuery.facebox(#{options[:html].to_json})"
+ else
+ page << "jQuery.facebox(#{s.to_json})"
+ end
if options[:msg]
page << "jQuery('#facebox .content').prepend('<div class=\"message\">#{options[:msg]}</div>')"

0 comments on commit 637dfce

Please sign in to comment.