Edit 뷰 작성
Edit 뷰는 작성된 포스트를 사용자에게 보여주고 포스트를 수정할 수 있는 폼을 제공한다. app/views/Post/Edit.html 파일을 생성하고 다음과 같이 코드를 작성해 보자.
▼ app/views/Post/Edit.html
{{set . “title” “Edit Post”}} {{template “header.html” .}} <form method=“POST” action=”{{url “Post.Update” .post.Id}}”> {{$post := .post}} {{with $field := field “title” .}} <div> <label for=“title”>Title</label> <input type=“text” id=“title” name=”{{$field.Name}}” placeholder=“Enter title” value=”{{if $field.Flash}}{{$field.Flash}}{{else}}{{$post.Title}}{{end}}”/> </div> {{end}} {{with $field := field “body” .}} <div> <label for=“title”>Body</label> <textarea id=“body” name=”{{$field.Name}}”> {{if $field.Flash}}{{$field.Flash}}{{else}}{{$post.Body}}{{end}} </textarea> </div> {{end}} <button type=“submit”>Update Post</button> </form> <a href=”{{url “Post.Show” .post.Id}}”>Show</a> <a href=”{{url “Post.Index”}}”>Back</a> {{template “footer.html” .}}