feat(example): add example app and blog app with demos

This commit is contained in:
dualfroz committed 2026-08-28 19:40:00 +02:00
1 parent 28e6bc3cf2
commit 7d2312b94b
13 files changed
+234

No files matched your search

@@ -0,0 +1,24 @@
class PostsController < Prism::Controller
layout :application
def index
render(:index, locals: { posts: Post.order(:created_at, :desc), notice: flash[:notice], errors: [] })
end
def show
render(:show, locals: { post: Post.find(params['id']) })
rescue Prism::Orm::RecordNotFound
halt(404, 'Post not found')
end
def create
post = Post.new(title: params['title'], body: params['body'])
if post.save
flash[:notice] = "Post ##{post.id} created"
redirect url_for(:posts)
else
status(422)
render(:index, locals: { posts: Post.order(:created_at, :desc), notice: nil, errors: post.errors.full_messages })
end
end
end
+3
View File
@@ -0,0 +1,3 @@
class Post < Prism::Orm::Model
validates :title, presence: true, length: { minimum: 3 }
end
@@ -0,0 +1,5 @@
<!doctype html>
<html>
<head><title><%= defined?(title) ? title : 'Prism App' %></title></head>
<body><%== content %></body>
</html>
+4
View File
@@ -0,0 +1,4 @@
<li class="post" id="post-<%= post.id %>">
<h2><%= post.title %></h2>
<p><%= post.body %></p>
</li>
+21
View File
@@ -0,0 +1,21 @@
<h1>Blog</h1>
<% if notice %>
<p class="notice"><%= notice %></p>
<% end %>
<% unless errors.empty? %>
<ul class="errors">
<% errors.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
<form method="post" action="/posts">
<input type="text" name="title" placeholder="Title">
<textarea name="body" placeholder="Body"></textarea>
<button type="submit">Create post</button>
</form>
<ul class="posts">
<% posts.each do |post| %>
<%== partial('post', locals: { post: post }) %>
<% end %>
</ul>
+2
View File
@@ -0,0 +1,2 @@
<h1><%= post.title %></h1>
<p><%= post.body %></p>