def create @post = Post.new( content: params[:content], user_id: @current_user.id, category: params[:category], title: params[:title], image_name: "default_post.jpg" ) if params[:image] @post.image_name = "#{@post.title}.jpg" image = params[:image] File.binwrite("public/post_images/#{@post.image_name}", image.read) end if @post.save redirect_to("/users/#{@current_user.id}") flash[:notice] = "投稿しました" else @content = params[:content] @title = params[:title] render("posts/new") end end
<div class="post-information"> <img src="<%= "/post_images/#{@post.image_name}" %>"> <h1><%= @post.title %></h1> <p><%= @post.content %></p> <div class="posted-date"> <%= @post.updated_at.strftime('%Y/%m/%d') %> </div> . . . </div>
何かお気づきの点があればご指摘をお願いします。