作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
基本上,我希望使链接能够从“收藏夹”动态刷新为“已删除”,同时让用户可以选择重新单击新按钮以返回上一步。但是确实会发生该操作,因为刷新页面时会显示更新的按钮。为什么单击“收藏此教室”链接无效? “删除此教室”链接似乎有效。谢谢你的帮助
favorite_controller.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
$("#favorite_classroom").html("<%= escape_javascript(link_to 'Remove the Classroom', classroom_favorite_path(@classroom), :remote => true, :method => :delete) %>");
<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"
最佳答案
您在js文件中两次使用了双引号。你不能那样做。您需要这样重写它-
$("#favorite_classroom").html("<%= escape_javascript(link_to 'Remove the Classroom', classroom_favorite_path(@classroom), :remote => true, :method => :delete) %>");
= link_to 'Remove Favorite', classroom_favorite_path([@classroom, @favorite]), :remote => true, :method => :delete
关于ruby-on-rails - 如何在Ruby on Rails中使用相同的.js更新重新创建远程链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11925615/
我是一名优秀的程序员,十分优秀!