Created
November 20, 2010 03:06
-
-
Save leaniman/707574 to your computer and use it in GitHub Desktop.
Renderizar una vista en un fancybox, muy útil para mostrar las validaciones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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