如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
railsnewblogcdblograilsgscaffoldposttitle:stringtext:textrailsgmodelcommentpost_id:integertext:textrakedb:migraterailss测试:HYPERLINK"http://localhost:3000/posts"http://localhost:3000/posts删除原有的内容,新的内容如下:<h1><%=@post.title%></h1><%=@post.text%><p><%=link_to"Back",posts_path%>|<%=link_to"Edit",edit_post_path(@post)%>|<%=link_to"Delete",@post,:method=>:delete,:confirm=>"Areyousure?"%></p>来源:HYPERLINK"http://blog.csdn.net/pan_tian/article/details/8763627"增加Comments项<h1><%=@post.title%></h1><%=@post.text%><h2>Comments</h2><%@post.comments.eachdo|comment|%><p><%=comment.text%></p><p><%=time_ago_in_wordscomment.created_at%>ago</p><%end%><%=form_for[@post,@post.comments.build]do|f|%><p><%=f.text_area:text,:size=>'40x10'%></p><p><%=f.submit"PostComment"%></p><%end%><p><%=link_to"Back",posts_path%>|<%=link_to"Edit",edit_post_path(@post)%>|<%=link_to"Delete",@post,:method=>:delete,:confirm=>"Areyousure?"%></p>增加has_many:comments增加belongs_to:postresources:postsdoresources:commentsend这个时候Comment就出来了,但是如果提交comment,还会报错,因为我们还没写comment的controller打开一个新的命令行D:\Ruby\projects>cdblogD:\Ruby\projects\blog>railsgcontrollercommentscreatedestroyclassCommentsController<ApplicationControllerdefcreate@post=Post.find(params[:post_id])@comment=@post.comments.build(comment_params)@comment.saveredirect_to@postenddefcomment_paramsparams.require(:comment).permit(:id,:text)enddefdestroyendend增加删除comment功能(增加DeleteComment链接)<h1><%=@post.title%></h1><%=@post.text%><h2>Comments</h2><%@post.comments.eachdo|comment|%><p><%=comment.text%></p><p><%=time_ago_in_wordscomment.created_at%>ago</p><p><%=link_to"DeleteComment",[@post,comment],:method=>:delete,:confirm=>"Areyousure?"%></p><%end%><%=form_for[@post,@post.comments.build]do|f|%><p><%=f.text_area:text,:size=>'40x10'%></p><p><%=f.submit"PostComment"%></p><%end%><p><%=link_to"Back",posts_path%>|<%=link_to"Edit",edit_post_path(@post)%>|<%=link_to"Del