ruby on rails教程:http://guides.rubyonrails.org/getting_started.html#listing-all-articles
我正在按照说明操作,但是模板没有渲染;
我确实尝试了多次复制和粘贴。请帮帮忙;我相信这只是一个小小的配置问题。到目前为止,教程中的一切都运行得很好。(可以显示单个文章,并创建一篇文章)
ps:使用ruby 2.3:
Jills-MacBook-Pro:blog jsinger$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin14]html看起来像这样:
Listing articles
<% @articles.each do |article| %> <% end %>
Title Text
<%= article.title %> <%= article.text %>(我保存了两篇文章)
my code is: index.html: (in app/views/articles)
<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>控制器:(blog/app/controllers/application_controller.rb)
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id]);
end
def home
@articles = Article.all
end
def new
end
def create
@article = Article.new(article_params)
@article.save
redirect_to @article
end
private
def article_params
params.require(:article).permit(:title,:text)
end
end发布于 2017-01-26 06:31:12
将ruby重命名为index.html.erb,以便可以解释嵌入的index.html。
https://stackoverflow.com/questions/41862808
复制相似问题