Мой первый проект на рубине на рельсах. Я получаю эту ошибку 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' opeations нет необходимости объявлять его снова –