게시물을 저장하려고 할 때마다이 오류가 표시됩니다.NoMethodError in PostsController # 정의되지 않은 메서드 'body'를 만듭니다.
여기 내 new.html.erb
파일입니다.
<div id="page_wrapper">
<h1>New Post</h1>
<%= form_for :post, url: posts_path do |f| %>
<% if @post.errors.any? %>
<div id="errors">
<h2><%= pluralize(@post.errors.count, "error") %> prevented this post from saving:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %><br>
</p>
<p>
<%= f.label :date %><br>
<%= f.text_field :date %><br>
</p>
<p>
<%= f.label :time %><br>
<%= f.text_field :time %><br>
</p>
<p>
<%= f.label :location %><br>
<%= f.text_field :location %><br>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
</div>
여기 내 show.html.erb
파일입니다.
<div id="page_wrapper">
<h1 class="title">
<%= @post.title %>
</h1>
<p class="date">
Submitted <%= time_ago_in_words(@post.created_at) %> Ago
</p>
<p class="time">
<%= @post.time %>
</p>
<p class="location">
<%= @post.location %>
</p>
</div>
여기 내 posts_controller.rb
파일입니다.
class PostsController < ApplicationController
def index
@posts = Post.all.order('created_at DESC')
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post
else
render 'new'
end
end
def show
@post = Post.find(params[:id])
end
private
def post_params
params.require(:post).permit(:title, :body, :location)
end
end
여성용의 내 routes.rb
파일
Rails.application.routes.draw do
resources :posts
root "posts#index"
end
당신의 schema.rb –
인사를 공유, 액티브 :: Schema.define (버전 : 20160812052026)는 힘을 CREATE_TABLE "게시물"을 수행합니다 : 캐스케이드 할 | t을 | t.string "제목" t.string "날짜" t.string "시간" t.text "위치" t.datetime "created_at", 널 (null) : 거짓 t.datetime "updated_at", 널 (null) : 거짓 끝 끝 – Bikal
@ArunKumar 내가 내 위의 오류 스크린 샷을 가지고, 그것은 나 제공 NoMethodError가 PostsController에서 #는 #에 대한 <포스트 : 0x007f3b81a787f8>을 정의되지 않은 메서드'몸 '을 만들어이 게시물 – Bikal