Skip to content

Instantly share code, notes, and snippets.

@leaniman
Created November 20, 2010 03:06
Show Gist options
  • Save leaniman/707574 to your computer and use it in GitHub Desktop.
Save leaniman/707574 to your computer and use it in GitHub Desktop.
Renderizar una vista en un fancybox, muy útil para mostrar las validaciones
En el application_controller.rb:
def render_to_fancybox(options)
html = render_to_string(options).to_json
render :update do |page|
page << "$.fancybox(#{html});"
end
end
En cualquier controlador:
Ejemplo usando inherited resources:
def create
create! do |success, failure|
success.html do
render :update do |page|
page << "$.fancybox.close()"
end
end
failure.html do
render_to_fancybox(:action => :new)
end
end
end
Ejemplo sin usar inherited resources:
def create
@post = Post.new(params[:post])
if @post.save
render :update do |page|
page << "$.fancybox.close()"
end
else
render_to_fancybox(:action => :new)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment