电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

rubyonrails创建一个博客项目

rubyonrails创建一个博客项目_第1页
1/6
rubyonrails创建一个博客项目_第2页
2/6
rubyonrails创建一个博客项目_第3页
3/6
精品文档---下载后可任意编辑rails new blogcd blograils g scaffold post title:string text:textrails g model comment post_id:integer text:textrake db:migraterails s测试:http://localhost:3000/posts精品文档---下载后可任意编辑删除原有的内容,新的内容如下:1.

<%= @post.title %>

精品文档---下载后可任意编辑2. 3. <%= @post.text %> 4. 5.

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.

<%= @post.title %>

2. 3. <%= @post.text %> 4. 5.

Comments

6. 7. <% @post.comments.each do |comment| %> 8.

<%= 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、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

rubyonrails创建一个博客项目

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部