再次加载
可以成功显示了
[root@h202 blog]# vim app/controllers/articles_controller.rb
[root@h202 blog]# cat app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def new
end
def create
# render plain: params[:article].inspect
# @article = Article.new(params[:article])
@article = Article.new(article_params)
@article.save
redirect_to @article
end
def show
@article = Article.find(params[:id])
end
def index
@articles = Article.all
end
private
def article_params
params.require(:article).permit(:title,:text)
end
end
[root@h202 blog]# vim app/views/articles/index.html.erb
[root@h202 blog]# cat app/views/articles/index.html.erb
<h1>Listing articles</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
</tr>
<% end %>
</table>
[root@h202 blog]#
访问 /articles
[root@h202 blog]# vim app/views/articles/index.html.erb
[root@h202 blog]# cat app/views/articles/index.html.erb
<h1>Link test!!!!</h1>
<%= link_to 'My Blog', controller: 'articles' %>
<%= link_to 'New article', new_article_path %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
</tr>
<% end %>
</table>
[root@h202 blog]# vim app/views/articles/show.html.erb
[root@h202 blog]# cat app/views/articles/show.html.erb
<p>
<strong>Title:</strong>
<%= @article.title %>
</p>
<p>
<strong>Text:</strong>
<%= @article.text %>
</p>
<%= link_to 'Back', articles_path %>
[root@h202 blog]# vim app/views/articles/new.html.erb
[root@h202 blog]# cat app/views/articles/new.html.erb
<h1>Test blog http://soft.dog/</h1>
<%= form_for :article, url: articles_path do |f| %>
<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 %>
<%= link_to 'Back', articles_path %>
[root@h202 blog]#
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。