mirror of
https://github.com/System-End/highway.git
synced 2026-04-20 00:25:16 +00:00
add basic posts
This commit is contained in:
parent
61d4dbd82f
commit
f7d8732ebc
18 changed files with 169 additions and 8 deletions
BIN
site/app/assets/images/logo.png
Normal file
BIN
site/app/assets/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 574 KiB |
|
|
@ -1,11 +1,12 @@
|
|||
/* Reset default margins and padding */
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%
|
||||
}
|
||||
|
||||
html {
|
||||
background-color: #272239;
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Ensure the image container takes full width */
|
||||
|
|
@ -50,6 +51,3 @@ img {
|
|||
|
||||
}
|
||||
|
||||
.container {
|
||||
padding-bottom: 64px;
|
||||
}
|
||||
46
site/app/controllers/posts_controller.rb
Normal file
46
site/app/controllers/posts_controller.rb
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
class PostsController < ApplicationController
|
||||
|
||||
before_action :set_post, only: %i[ show edit update ]
|
||||
|
||||
def index
|
||||
@posts = Post.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@post = Post.new
|
||||
end
|
||||
|
||||
def create
|
||||
@post = Post.new(post_params)
|
||||
if @post.save
|
||||
redirect_to @post
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @post.update(post_params)
|
||||
redirect_to @post
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_post
|
||||
@post = Post.find(params[:id])
|
||||
end
|
||||
|
||||
def post_params
|
||||
params.expect(post: [ :name ])
|
||||
end
|
||||
|
||||
end
|
||||
2
site/app/helpers/posts_helper.rb
Normal file
2
site/app/helpers/posts_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module PostsHelper
|
||||
end
|
||||
3
site/app/models/post.rb
Normal file
3
site/app/models/post.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Post < ApplicationRecord
|
||||
validates :name, presence: true
|
||||
end
|
||||
|
|
@ -1,3 +1,25 @@
|
|||
<h1 class="text-3xl font-bold underline text-white">
|
||||
Hello world!
|
||||
</h1>
|
||||
<div class="feed-container" style="display: flex; height: 100vh;">
|
||||
|
||||
<div class="w-64 bg-[#2E2A54] text-white p-5">
|
||||
|
||||
<%= image_tag "logo.png", class: "w-full mb-8" %>
|
||||
|
||||
|
||||
<div class="text-center grid grid-cols-1 gap-2">
|
||||
<div class="hover:bg-[#564CAD] border-2 border-[#564CAD] p-2 rounded-lg transition duration-100">Main</div>
|
||||
<div class="hover:bg-[#564CAD] border-2 border-[#564CAD] p-2 rounded-lg transition duration-100">User</div>
|
||||
<div class="hover:bg-[#564CAD] border-2 border-[#564CAD] p-2 rounded-lg transition duration-100">Leaderboards</div>
|
||||
<div class="hover:bg-[#564CAD] border-2 border-[#564CAD] p-2 rounded-lg transition duration-100">Info</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="main-content" style="flex: 1; padding: 20px;">
|
||||
<div class="flex-col">
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<main class="container mx-auto mt-28 px-5 flex">
|
||||
<main class="">
|
||||
<%= yield %>
|
||||
</main>
|
||||
</body>
|
||||
|
|
|
|||
13
site/app/views/posts/_form.html.erb
Normal file
13
site/app/views/posts/_form.html.erb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
<%= form_with model: @post do |form|%>
|
||||
<div>
|
||||
<%= form.label :name %>
|
||||
<div class="">
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.submit%>
|
||||
</div>
|
||||
<% end %>
|
||||
4
site/app/views/posts/edit.html.erb
Normal file
4
site/app/views/posts/edit.html.erb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<h1>Edit post</h1>
|
||||
|
||||
<%= render "form", post: @post %>
|
||||
<%= link_to "Cancel", @post %>
|
||||
13
site/app/views/posts/index.html.erb
Normal file
13
site/app/views/posts/index.html.erb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<h1>Posts</h1>
|
||||
|
||||
<%= link_to "New Post", new_post_path%>
|
||||
|
||||
<div>
|
||||
<% @posts.each do |post|%>
|
||||
<div class="bg-[#2E2A54]">
|
||||
<a href="/posts/<%= post.id %>">
|
||||
<%= link_to post.name, post %>
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
4
site/app/views/posts/new.html.erb
Normal file
4
site/app/views/posts/new.html.erb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<h1>New post</h1>
|
||||
|
||||
<%= render "form", post: @post%>
|
||||
<%= link_to "Cancel", posts_path%>
|
||||
4
site/app/views/posts/show.html.erb
Normal file
4
site/app/views/posts/show.html.erb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<%= link_to "Back", posts_path %>
|
||||
<%= link_to "Edit", edit_post_path(@post)%>
|
||||
|
||||
<h1><%= @post.name %></h1>
|
||||
|
|
@ -13,4 +13,7 @@ Rails.application.routes.draw do
|
|||
root "landing#index"
|
||||
|
||||
get "/feed", to: "feed#show"
|
||||
|
||||
resources :posts
|
||||
|
||||
end
|
||||
|
|
|
|||
9
site/db/migrate/20250425185735_create_posts.rb
Normal file
9
site/db/migrate/20250425185735_create_posts.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class CreatePosts < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :posts do |t|
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
19
site/db/schema.rb
generated
Normal file
19
site/db/schema.rb
generated
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# This file is the source Rails uses to define your schema when running `bin/rails
|
||||
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
||||
# be faster and is potentially less error prone than running all of your
|
||||
# migrations from scratch. Old migrations may fail to apply correctly if those
|
||||
# migrations use external dependencies or application code.
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_04_25_185735) do
|
||||
create_table "posts", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
end
|
||||
7
site/test/controllers/posts_controller_test.rb
Normal file
7
site/test/controllers/posts_controller_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
site/test/fixtures/posts.yml
vendored
Normal file
7
site/test/fixtures/posts.yml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
name: MyString
|
||||
7
site/test/models/post_test.rb
Normal file
7
site/test/models/post_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue