remote 收藏
view
<%= javascript_include_tag 'jquery' %><%= javascript_include_tag 'jquery_ujs' %><script type="text/javascript">$(function(){ $('.favorite').bind('ajax:success', function() { $(this).fadeOut(); });});</script>
<% unless FavEvent.where('event_id = ? and uid = ?', @event.id, current_uid).any? -%> <%= link_to "收藏", "/user_center/fav_events?event_id=#{@event.id}", class: 'favorite', method: :post, remote: true %><% end -%>
namespace "user_center" do resources :fav_eventsend
def index @fav_events = FavEvent.where('uid = ?', current_uid).order('event_id desc').page(params[:page]).per(6)enddef create unless FavEvent.where('event_id = ? and uid = ?', params[:event_id], current_uid).any? event = Event.find(params[:event_id]) FavEvent.create(event_id: event.id, uid: current_uid) end respond_to do |format| format.js { render :nothing => true } endenddef destroy @fav_event = FavEvent.find(params[:id]) @fav_event.destroy redirect_to user_center_fav_events_urlend
<ul id="fav_events"> <%= render @fav_events %></ul><div id="paginator"> <%= paginate @fav_events, :remote => true %></div>
<li> <img src="<%= url('../../../images/common/perform_lists_photo.jpg') %>" alt="remote 珍藏" width="220" height="130" /> <p> <%= link_to "取消收藏", "/user_center/fav_events/#{fav_event.id}", class: 'cancel_favorite', method: :delete, remote: true %> </p> </li>
window.location.hash = '#fav_events';$('#fav_events').html('<%= escape_javascript render(@fav_events) %>');$('#paginator').html('<%= escape_javascript(paginate(@fav_events, :remote => true).to_s) %>');