简体   繁体   中英

ruby on rails tutorial:stuck on listing all articles

ruby on rails tutorial: http://guides.rubyonrails.org/getting_started.html#listing-all-articles

I'm following the directions, but the template is not rendering;

I did try copy and pasting multiple times. please help; I'm sure it's a small configuration thing. everything up until now in the tutorial works fine. (can show an individual article, and create one)

ps: using ruby 2.3:

Jills-MacBook-Pro:blog jsinger$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin14]

the html looks like:

Listing articles

<% @articles.each do |article| %> <% end %>
Title   Text
<%= article.title %>    <%= article.text %>

(I have two articles saved)

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>

controller: (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

将index.html重命名为index.html.erb,以便可以解释嵌入的ruby。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM