【发布时间】:2013-02-25 11:07:10
【问题描述】:
当我浏览到我的索引页面时遇到路由错误。我设置了一些简单的东西,模型有: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 看起来像往常一样。
routes.rb
NotePad::Application.routes.draw do
resources :posts
任何帮助都会非常有用。
【问题讨论】:
-
我看到的只有
new:@post.new应该是@post = Post.new
标签: ruby-on-rails ruby