現在railsでブログアプリを作成中の初心者です。
どなたかこのエラーの解決方法がわかるかたはいらっしゃいませんか?
おそらくENDの位置とかだとは思うのですが、ご教示願います。
初心者なりに考えていたのが、showControllerで何か問題が
あるのではないかと推測しております。
PostsController コード
class PostsController < ApplicationController
GET /posts/new
def new
@post = Post.new
end
POST /posts
def create
@post = Post.new(post_params)
if @post.save redirect_to @post else render :new, status: :unprocessable_entity end
end
# GET /posts/:id def show @post = Post.find(params[:id]) end # GET /posts def index @posts = Post.all end # GET /posts/:id/edit def edit @post = Post.find(params[:id]) end # PATCH /posts/:id # PUT /posts/:id def update @post = Post.find(params[:id]) if @post.update(post_params) redirect_to @post else render :edit, status: :unprocessable_entity end end # DELETE /posts/:id
def destroy
@post = Post.find(params[:id])
@post.destroy
redirect_to posts_path
end
private
def post_params
params.require(:post).permit(:title, :text)
end
show.html.erbコード
<p> <strong>タイトル:</strong> <%= @post.title %> </p> <p> <strong>内容:</strong> <%= @post.text %> </p> <h2>コメント</h2> <% @post.comments.each do |comment| %> <p> <strong>コメンター:</strong> <%= comment.commenter %> </p> <p> <strong>コメント:</strong> <%= simple_format comment.body %> </p><% end %>
<h2>コメントを追加</h2> <%= form_for( [@post, @post.comments.build] ) do |f| %> <p> <%= f.label :commenter, "コメンター" %><br /> <%= f.text_field :commenter %> </p> <p> <%= f.label :body, "コメント" %><br /> <%= f.text_area :body, cols: 60, rows: 8 %> </p> <p> <%= f.submit, "コメント投稿" %> </p> <% end %><%= link_to '戻る', posts_path %>
<%= link_to '編集', edit_post_path(@post) %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/11 22:30