admin管理员组文章数量:1415119
How e the destroy action is inpatible once jquery is required in the application.js file? How do you get the destroy action to work again without disregarding jquery?
posts index view:
h1 Blog
- @posts.each do |post|
h2 = link_to post.title, post
p = post.content
p = link_to 'Edit', edit_post_path(post)
p = link_to 'Delete', post, data: {confirm: "Are you sure?"}, method: :delete
br
p = link_to 'Add a new post', new_post_path
destroy action in posts controller:
def destroy
@post = Post.find params[:id]
@post.destroy
redirect_to posts_path, :notice => "Your post has been deleted"
end
application.js:
= require jquery
= require jquery_ujs
//= require turbolinks
//= require_tree
As soon as I ment those two out the destroy action works again. Without the ment, the delete link just fires the show action...your thoughts?
How e the destroy action is inpatible once jquery is required in the application.js file? How do you get the destroy action to work again without disregarding jquery?
posts index view:
h1 Blog
- @posts.each do |post|
h2 = link_to post.title, post
p = post.content
p = link_to 'Edit', edit_post_path(post)
p = link_to 'Delete', post, data: {confirm: "Are you sure?"}, method: :delete
br
p = link_to 'Add a new post', new_post_path
destroy action in posts controller:
def destroy
@post = Post.find params[:id]
@post.destroy
redirect_to posts_path, :notice => "Your post has been deleted"
end
application.js:
= require jquery
= require jquery_ujs
//= require turbolinks
//= require_tree
As soon as I ment those two out the destroy action works again. Without the ment, the delete link just fires the show action...your thoughts?
Share Improve this question asked Oct 16, 2013 at 2:49 Ryan WaitsRyan Waits 3071 gold badge6 silver badges18 bronze badges 2- found a solution here by using the button_to method rather than link_to. button_to allows you to create a form using put, post, and delete without enabling javascript. – Ryan Waits Commented Oct 16, 2013 at 4:55
-
You can also use
data-method=delete
instead of going for button (because it may require further styling to suit your needs) – Steve Robinson Commented Oct 16, 2013 at 4:58
3 Answers
Reset to default 3So the asset pipeline does something special with those ments. The presence of a ment of the form
//= require jquery
instructs the preprocessor to include that file when building the application.js as served up to clients of the application. When you remove the ment, you're removing this behavior - and the resulting libraries are not piled into the final application.js served up by the app.
The upshot of this is that you're misinterpreting how the required directive works. It ONLY works inside a ment. When you remove the ment tag you stop including the library.
application.js
is a manifest file so the syntax is suppose to have those ments. See http://guides.rubyonrails/asset_pipeline.html#manifest-files-and-directives
If you copied and pasted the code from the website http://guides.rubyonrails/getting_started.html, try to type it in instead.
Or delete all the leading 'whitespaces' which may not be whitespaces. Somehow I got ascii 160 instead ascii 32 (the whitespace character).
I'm sure how it happen but copy and paste it again is working fine now.
本文标签:
版权声明:本文标题:javascript - rails 4, link_to not working with destroy action when jquery, jquery_ujs is required - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745198446a2647252.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论