インデックス ページを参照すると、ルーティング エラーが発生します。モデルには:title (string)
と:content(text)
.
index.html.erb
<h1>Listing all notes</h1>
<% @posts.each do |post| %>
<h2><%= link_to post.title, post %></h2>
<p><%= post.content %></p>
<hr/>
<% end %>
<small><%= link_to "Add New Note", new_post_path %></small>
<small><%= link_to "Edit", edit_post_path(@post) %></small>
post_controller.rb
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post.new
end
def create
@post = Post.new(params[:post])
if @post.save
redirect_to posts_path, :notice => "Your Note was Saved!"
else
render "new"
end
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to posts_path
else
render "edit"
end
end
でアプリを参照すると、:3000/posts
次のエラーが表示されます。
{:controller="posts", :action="show"} に一致するルートはありません
私の routes.rb はいつものように見えます。
ルート.rb
NotePad::Application.routes.draw do
resources :posts
どんな助けでも非常に役に立ちます。