肖威洞察 | Ruby on Rails 的快速學習的體系框架;
Ruby on Rails 的快速學習的體系框架;
參考案例體系:
https://ruby-china.github.io/rails-guides/getting_started.html
https://www.techotopia.com/index.php/Ruby_Essentials
Ruby on Rails 程式設計體系的技能體系的學習的關鍵所在在於:
新手階段 10% ;
1、Ruby 的後端結構的體系的學習;
2、Rails 的前端框架的體系的學習;
3、Ruby on Rails 的案例體系的訓練 ;
高階新手階段 59% ;
4、針對於存在的案例給與專案的復現;
勝任者 20% ;精通者階段 10% ;
5、針對於不存在的案例使用皮膚完成專案分解,從而打造自己的專案;
專家階段 1% ;
6、針對於別人的專案的問題,快速的給與解決的方法和答疑
新建一個專欄
rails new blog
cd blog
git init
git add .
git commit -m "commit initial"
構建一個首頁
bin/rails generate controller Welcome index
atom .
rails s
touch app/views/welcome/index.html.erb
<h1>Hello, Rails!</h1>
config/routes.rb
Rails.application.routes.draw do
root 'articles#index'
resources :articles
end
構建文章列表
git checkout -b add_articles
bin/rails generate controller Articles
bin/rails generate model Article title:string text:text
bin/rails db:migrate
rails s
git add .
git commit -m "add articles"
app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
@article = Article.new
end
def edit
@article = Article.find(params[:id])
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
private
def article_params
params.require(:article).permit(:title, :text)
end
end
touch app/views/articles/index.html.erb
<h1>Hello, Rails!</h1>
<%= link_to 'My Blog', controller: 'articles' %>
<h1>Listing Articles</h1>
<%= link_to 'New article', new_article_path %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th colspan="3"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
app/views/articles/-form.html.erb
<%= form_for @article do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@article.errors.count, "error") %> prohibited
this article from being saved:
</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
app/views/articles/show.html.erb
<p>
<strong>Title:</strong>
<%= @article.title %>
</p>
<p>
<strong>Text:</strong>
<%= @article.text %>
</p>
<h2>Comments</h2>
<%= render @article.comments %>
<h2>Add a comment:</h2>
<%= render 'comments/form' %>
<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>
app/views/articles/new.html.erb
<h1>New article</h1>
<%= render 'form' %>
<%= link_to 'Back', articles_path %>
app/views/articles/edit.html.erb
<h1>Edit article</h1>
<%= render 'form' %>
<%= link_to 'Back', articles_path %>
構建評論頁面
git checkout -b add_comments
bin/rails generate model Comment commenter:string body:text article:references
bin/rails db:migrate
bin/rails generate controller Comments
rails s
config/routes.rb
Rails.application.routes.draw do
root 'articles#index'
resources :articles do
resources :comments
end
end
app/models/article.rb
class Article < ApplicationRecord
has_many :comments, dependent: :destroy
validates :title, presence: true,
length: { minimum: 5 }
end
app/models/comment.rb
class Comment < ApplicationRecord
belongs_to :article
end
app/controllers/comments_controller.rb
class CommentsController < ApplicationController
def create
@article = Article.find(params[:article_id])
@comment = @article.comments.create(comment_params)
redirect_to article_path(@article)
end
def destroy
@article = Article.find(params[:article_id])
@comment = @article.comments.find(params[:id])
@comment.destroy
redirect_to article_path(@article)
end
private
def comment_params
params.require(:comment).permit(:commenter, :body)
end
end
app/views/comments/-comment.html.erb
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<p>
<%= link_to 'Destroy Comment', [comment.article, comment],
method: :delete,
data: { confirm: 'Are you sure?' } %>
</p>
app/views/comments/-form.html.erb
<%= form_for([@article, @article.comments.build]) do |f| %>
<p>
<%= f.label :commenter %><br>
<%= f.text_field :commenter %>
</p>
<p>
<%= f.label :body %><br>
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
上傳程式碼倉庫和雲端專案部署
git remote add origin https://github.com/shenzhoudance/xiaoweiblog.git
git push --all origin
相關文章
- 肖威洞察 | 如何做好區塊鏈行業的教育體系區塊鏈行業
- 肖威洞察 | 商業社會的深度思考
- Ruby on Rails 生成指定版本的 Rails 專案AI
- rails on ruby,ruby on rails 之程式碼塊(二)AI
- 肖威洞察 | 時間自由的九大段位
- 肖威洞察 | 針對於 SUPERXSCHOOL 的後續進展
- ruby on rails 小技巧AI
- Ruby on Rails Ping ++ 支付AI
- Rails並不是用Ruby編寫的AI
- 肖威洞察 | 2.5 個人如何開發一款跨終端的產品?[Ruby Tuesday 的分享] · 簡單心理技術團隊...
- Ruby on Rails中的MVC架構是如何工作的AIMVC架構
- ruby on rails筆記和理解AI筆記
- Ruby on Rails Mountable vs. Full EngineAI
- Ruby on rails專案中 引入BootstrapAIboot
- 強大的Rails/Ruby開發工具:JetBrains RubyMine 2023 for macAIMac
- 從NodeJS切換到Ruby on Rails - nikodunkNodeJSAI
- 肖威洞察 | App Development (iOS11, Swift 4, Xcode 9): Ultimate Udemy Playlist (2018)APPdeviOSSwiftXCode
- 肖威洞察 |MiiX活動執行手冊:任務分解情況(2018.11.30)
- 開發新手最容易犯的50個 Ruby on Rails 錯誤(1)AI
- 分享一款免費體驗的快速開發框架,可以學習用!框架
- 從底層去認識 ruby 的load,require,gems,bundler,以及rails中的autoloadingUIAI
- [轉載] 快速學習-Mybatis框架概述MyBatis框架
- 【Ruby on Rails全棧課程】2.7 塊(Block)和迭代器AI全棧BloC
- [Ruby Summit 2018 話題分享] 模組化的 Rails,微服務以外的另一種選擇MITAI微服務
- 深度學習框架新手快速上手指南深度學習框架
- Laravel 框架學習心得體會Laravel框架
- 幽默:Ruby on Rails團隊提出Rail治理名單引發爭議AI
- 肖sir__po框架之ui自動化框架框架UI
- 幽默:Ruby on Rails建立者DHH質疑無伺服器和微服務AI伺服器微服務
- keras框架下的深度學習(一)手寫體識別Keras框架深度學習
- rails graphql的使用AI
- paoding-rose框架的學習ROS框架
- 最值得學習的Python框架Python框架
- 基於Cucumber框架的學習框架
- caffe整體框架的學習的部落格,這個部落格山寨了一個caffe框架框架
- 從0使用Ruby on Rails打造企業級RESTful API專案實戰之我的雲音樂AIRESTAPI
- 駁 《駁 《駁 《駁 《停止學習框架》》》》、《駁 《駁 《停止學習框架》》》、《駁 《停止學習框架》》、《停止學習框架》框架
- Ruby on Rails 動態渲染遠端程式碼執行漏洞 (CVE-2016-0752)AI