Đang chuẩn bị liên kết để tải về tài liệu:
railsspace building a social networking website with ruby on rails phần 10

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Nhiệm vụ bình luận ở trên cùng của tạo đảm bảo rằng bản sao? có tất cả các id nó cần (Mục 16.1.2) 0,8 RJS trong trường hợp này phục hồi liên kết "Thêm một lời" bằng cách sử dụng page.show (nghịch đảo của page.hide) trong khi thay thế HTML trong div ý kiến với kết quả trong việc xử lý | Simpo PDF Merge and Split Unregistered Version - http www.simpopdf.com 16.2 Beginning Ajax 491 Listing 16.13 app controllers comments_controller.rb def create comment Comment.new params comment ỗcomment.user User.find session user_id comment.post post respond_to do format if comment.duplicate or post.comments comment format.js do render update do page page.replace_html comments_for_post_ post.id partial comments comment collection post.comments page.show add_comment_link_for_post_ post.id page.hide new_comment_form_for_post_ post.id end end else format.js render nothing true end end end The comment assignments at the top of create ensure that duplicate has all the ids it needs Section 16.1.2 .8 The RJS in this case restores the Add a comment link using page.show the inverse of page.hide while replacing the HTML in the comments div with the result of rendering all of the comments again. A second possibility would be to use page.insert_html bottom comments_for_post_ post.id partial comments comment to insert the new comment at the bottom of the comments list Figure 16.3 . The reason we elected to rerender all the comments is because someone else might have submitted a comment while we were filling out ours this way each user always gets to see all the comments. In the case of an invalid comment e.g. a blank body we still need something to respond to the request. Since keeping the form on the page is a sensible behavior we can just render nothing with render nothing true 8 As a result we could actually replace the array append operation post.comments comment with a simple comment.save but we find the former more suggestive. Simpo PDF Merge and Split Unregistered Version - http www.simpopdf.com 492 Chapter 16 Blog comments with Ajax Figure 16.3 The form goes away and the comment shows up. This silent error assumes that the user can figure out the problem if he tries to submit a blank comment.9 16.2.3 Destroying comments From the typical user s point of view comments .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.