Created
June 9, 2009 14:21
-
-
Save mateuslinhares/126536 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## 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