我在添加帖子链接时遇到了问题。
My code for index is :-
<h1>Listing posts</h1>
<%= link_to 'new post',new_post_path %>
<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>
<h1> hello rails </h1>
<%= link_to "my blog",controller: "posts" %>
<p>Find me in app/views/welcome/index.html.erb</p>
my code for post_controller is:-
class PostsController < ApplicationController
def index
@posts=post.all
end
def new
end
def create
@post=Post.new(params[:post].permit(:title,:text))
@post.save
redirect_to @post
#render text: params[:post].inspect
end
def show
@post=Post.find(params[:id])
end
private
def post_params
params.require(:post).permit(:title,:text)
end
end
显示的错误是“未定义的局部变量或方法 `post' for #”请帮我跟踪错误