Dynamically "attach" a form in Rails 4 -
Assume that I have a The method of "brute force" will have to attach a form to each Thanks, Roy (P.S. - A good example would be FB page in which a user can comment on each post in the timeline, and I think having a form for each one Is not due to ...) You can find JS & amp; Ajax, like this: post model that has several comments where all the posts were shown In the
post # index page, I want to allow users to add their comments for specific posts (I know that it does not matter much, this is a common idea) .
post element, but this is bad stinking. I'm sure there are better options which I can not think of now Therefore, appreciate the help, therefore.
# config / routes.rb Resources: Post resources are: Comments # app / assets / javascript / application.js $ (document) expired .on (click " "," A.new_comment ", function () {# id = $ (this) .attr (" id "); $ .ajax ({url: $ (this) .attr (" href "); success: function ( Data) {$ ("#" + ID) .append (data);}});}); #app / idea / post / index.html. ARB & lt;% @ posts.each do | Post | & Gt%; & Lt;% = post.title% & gt; & Lt;% = link_to "Add comment", new_post_comment_path (post.id), category: "new_comment", id: post.id% & gt; & Lt;% end% & gt; #Apps/Controller/Content_Controller Rb def new @ comment = comment.nup_report_to do it Format | Format.html {Layer Render:! Request.xhr? } End End
Comments
Post a Comment