6. <%= link_to "Back", posts_path %> 7. | 8. <%= link_to "Edit", edit_post_path(@post) %> 9. | 10. <%= link_to "Delete",@post,:method => :delete, :confirm => "Are you sure?" %> 11.
来源: 增加 Comments 项1.<%= comment.text %>
9.<%= time_ago_in_words comment.created_at %> ago
10. <% end %> 11. 12. <%= form_for [@post,@post.comments.build] do |f| %> 13.<%= f.text_area :text, :size => '40x10' %>
14.<%= f.submit "Post Comment" %>
15. <% end %> 16. 17.18. <%= link_to "Back", posts_path %> 19. | 20. <%= link_to "Edit", edit_post_path(@post) %> 21. | 22. <%= link_to "Delete",@post,:method => :delete, :confirm => "Are you sure?" %> 23.
1.2. 增加 has_many :comments 增加 belongs_to :post 1. resources :posts do 2. resources :comments 3. end 这个时候 Comment 就出来了,但是假如提交 comment,还会报错,因为我们还没写 comment 的controller打开一个新的命令行D:\Ruby\projects>cd blogD:\Ruby\projects\blog>rails g controller comments create destroy精品文档---下载后可任意编辑1. class CommentsController < ApplicationController 2. def create 3. @post = Post.find(params[:post_id]) 4. @comment = @post.comments.build(comment_params) 5. @comment.save 6. 7. redirect_to @post 8. end 9. def comment_params params.require(:comment).permit(:id, :text)end10. def destroy 11. end 12....1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。
碎片内容