我在轨道上的红宝石的第一个项目。我得到这个错误ActiveRecord :: RecordNotFound
我print.html.erb是一个静态page.It有一个链接<a href="posts/index">Show</a>
和打印页面在我的情况下,索引页即本地主机:3000打开打印页面。
这是我index.html.erb页面(这是链接的页面)
<h1>Listing posts</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.text %></td>
</tr>
<% end %>
</table>
这是我的控制器
class PostsController < ApplicationController
def index
@posts = Post.all
end
def new
end
def create
@post = Post.new(post_params)
@post.save
redirect_to @post
end
def post_params
params.require(:post).permit(:title, :text)
end
def show
@post = Post.find(params[:id])
end
def print
end
end
这是我的路线文件
Watermark::Application.routes.draw do
resources :posts
root "posts#print"
post 'posts/index' => 'posts#index'
post ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
end
我想问题是在路线文件。
HTTP动词类似'get','post'声明应该放在'resouce:post'和'resouce:post'后面,以处理所有'CURD'操作,不需要再次声明它 –