Add posts test

This commit is contained in:
hannah.dagemark 2025-05-23 14:14:30 +02:00
commit 76229c8cc5
17 changed files with 278 additions and 0 deletions

View file

@ -0,0 +1,27 @@
<%= form_with(model: post) do |form| %>
<% if post.errors.any? %>
<div style="color: red">
<h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% post.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form.label :title, style: "display: block" %>
<%= form.text_field :title %>
</div>
<div>
<%= form.label :body, style: "display: block" %>
<%= form.textarea :body %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>

View file

@ -0,0 +1,12 @@
<div id="<%= dom_id post %>">
<p>
<strong>Title:</strong>
<%= post.title %>
</p>
<p>
<strong>Body:</strong>
<%= post.body %>
</p>
</div>

View file

@ -0,0 +1,2 @@
json.extract! post, :id, :title, :body, :created_at, :updated_at
json.url post_url(post, format: :json)

View file

@ -0,0 +1,12 @@
<% content_for :title, "Editing post" %>
<h1>Editing post</h1>
<%= render "form", post: @post %>
<br>
<div>
<%= link_to "Show this post", @post %> |
<%= link_to "Back to posts", posts_path %>
</div>

View file

@ -0,0 +1,16 @@
<p style="color: green"><%= notice %></p>
<% content_for :title, "Posts" %>
<h1>Posts</h1>
<div id="posts">
<% @posts.each do |post| %>
<%= render post %>
<p>
<%= link_to "Show this post", post %>
</p>
<% end %>
</div>
<%= link_to "New post", new_post_path %>

View file

@ -0,0 +1 @@
json.array! @posts, partial: "posts/post", as: :post

View file

@ -0,0 +1,11 @@
<% content_for :title, "New post" %>
<h1>New post</h1>
<%= render "form", post: @post %>
<br>
<div>
<%= link_to "Back to posts", posts_path %>
</div>

View file

@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>
<%= render @post %>
<div>
<%= link_to "Edit this post", edit_post_path(@post) %> |
<%= link_to "Back to posts", posts_path %>
<%= button_to "Destroy this post", @post, method: :delete %>
</div>

View file

@ -0,0 +1 @@
json.partial! "posts/post", post: @post