Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Rails 3 and 4 View Update with jQuery (Update rating pages)

An Duong edited this page Dec 27, 2013 · 1 revision

Since the README has the old rjs option using page.replace_html..., it just doesn't work with Rails 3 and jQuery. So the following makes it work. It will work with Rails 4 too.

rate action

def rate
  @video = Video.find(params[:id])
  @video.rate(params[:stars], current_user, params[:dimension])
  respond_to do |format|
    format.js
  end
end

rate.js.erb (put this file in Views folder of controller#action. For example: views/videos/rate.js.erb)

$("#<%= @video.wrapper_dom_id(params) %>").html("<%= escape_javascript(ratings_for(@video, params.merge(:wrap => false))) %>");
$("#<%= @video.wrapper_dom_id(params) %>").effect("highlight",{},3000);