基本上我想让一个链接能够从“收藏”动态刷新到“已删除”,同时让用户可以选择通过重新单击新按钮返回。该操作确实发生了,因为当我刷新页面时,更新的按钮会显示。为什么点击“收藏此课堂”链接不起作用?“删除此教室”链接似乎有效。谢谢你的帮助
收藏夹控制器.rb:
def create
current_classroom.add_to_favorites(@classroom)
current_classroom.save
respond_to do |format|
format.js { }
format.html {redirect_to @classroom}
end
end
def destroy
current_classroom.remove_from_favorites(@classroom)
current_classroom.save
respond_to do |format|
format.js { }
format.html {redirect_to @classroom}
end
end
收藏夹/create.js.erb
$("#favorite_classroom").html("<%= escape_javascript(link_to 'Remove the Classroom', classroom_favorite_path(@classroom), :remote => true, :method => :delete) %>");
教室/_classroom_details.html.erb
<div id="favorite_classroom">
<% if loggedin_user.favorite_classroom?(@classroom) %>
<%= link_to 'Remove this Classroom', classroom_favorite_path(@classroom), :remote => true, :method => :delete %>
<% else %>
<%= link_to 'Favorite this Classroom', classroom_favorites_path(@classroom), :remote => true, :method => :post %>
<% end %>
路线:
classroom_favorites POST /classrooms/:classroom_id/favorites(.:format) {:action=>"create", :controller=>"favorites"}
classroom_favorite DELETE /classrooms/:classroom_id/favorites/:id(.:format) {:action=>"destroy", :controller=>"favorites"}
单击“收藏此教室”链接时出错:
ActionView::Template::Error (No route matches {:action=>"destroy", :controller=>"favorites"
谢谢!