Skip to content

Instantly share code, notes, and snippets.

@mateuslinhares
Created June 9, 2009 14:21
Show Gist options
  • Save mateuslinhares/126536 to your computer and use it in GitHub Desktop.
Save mateuslinhares/126536 to your computer and use it in GitHub Desktop.
## Controller
def rate
@book = Book.find(params[:id])
@book.rate params[:rating].to_i
render :update do |page|
page.replace_html("rating", {:partial => "rate", :locals => {:rateable => @book}})
page.show "success_rating"
end
end
## Criar partial:
#erb (views/books/_rate.html.erb)
<%= render_ajax_rating rateable %>
<%= image_tag "icons/spinner.gif", :id => :spinner, :style => "display: none;" %>
<div id="success_rating" style="display:none;">
Voto computado!
</div>
#haml (views/books/_rate.html.haml)
= render_ajax_rating rateable
= image_tag "icons/spinner.gif", :id => :spinner, :style => "display: none;"
%p.success#success_rating{:style => "display:none;"}
Voto computado!
## Usar partial na view:
#erb
<div id="rating">
<%= render :partial => "books/rate", :locals => { :rateable => @book } %>
</div>
#haml
#rating
render :partial => "books/rate", :locals => { :rateable => @book }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment