Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Rails 2.3 star rating widget
  2. <%= hidden_field_tag("lot_id", lot.id) %>
  3. <%= f.submit :Submit %>
  4.        
  5. def create
  6.         lot = Lot.find_by_id(params[:lot_id])
  7.  
  8.             @rating = Rating.new(params[:rating])
  9.             @rating.lot_id = @lot.id
  10.             @rating.user_id = current_user.id
  11.             if @rating.save
  12.                 flash[:notice] = "your rating has been saved"
  13.                 redirect_to :id => nil                  
  14.  
  15.             end
  16.     end
  17.  
  18.     def update
  19.         lot = Lot.find_by_id(params[:lot_id])
  20.  
  21.             @rating = current_user.ratings.find_by_photo_id(@photo.id)
  22.             if @rating.update_attributes(params[:rating])
  23.                 flash[:notice] = "your rating has been saved"
  24.                 redirect_to :id => nil
  25.  
  26.             end
  27.  
  28.         end
  29.     end