polishing stories views

This commit is contained in:
Torsten 2023-01-11 20:52:58 +02:00
parent 23a2254d2e
commit 0055de6c83
14 changed files with 90 additions and 80 deletions

View File

@ -3,7 +3,7 @@ class StoriesController < ApplicationController
# GET /stories
def index
@stories = Story.all
@stories = Story.all.page params[:page]
end
# GET /stories/1
@ -22,6 +22,7 @@ class StoriesController < ApplicationController
# POST /stories
def create
@story = Story.new(story_params)
@story.member = current_member
if @story.save
redirect_to @story, notice: "Story was successfully created."

View File

@ -1,7 +1,12 @@
require "redcarpet"
module ApplicationHelper
include Merged::ViewHelper
def prose_classes
classes = "prose lg:prose-lg "
classes += "prose-headings:text-inherit "
{ class: classes }
end
def renderer
options = {hard_wrap: true , autolink: true, no_intra_emphasis: true ,

View File

@ -4,7 +4,7 @@ module MembersHelper
if someone.picture.blank?
image = asset_url("no_image")
else
image = element.picture.url
image = someone.picture.url
end
image_tag(image , alt: someone.name , class: classes )
end

View File

@ -5,6 +5,7 @@ class Member < ApplicationRecord
:recoverable, :rememberable, :validatable
mount_uploader :picture, PictureUploader
has_many :stories
def admin
true

View File

@ -1,2 +1,9 @@
class Story < ApplicationRecord
belongs_to :member
mount_uploader :picture, PictureUploader
def name
header
end
end

View File

@ -17,11 +17,19 @@
%svg.inline-block.w-3.ml-2{:fill => "currentColor", :viewbox => "0 0 12 12"}
%path{:d => "M9.707,5.293l-5-5A1,1,0,0,0,3.293,1.707L7.586,6,3.293,10.293a1,1,0,1,0,1.414,1.414l5-5A1,1,0,0,0,9.707,5.293Z"}
.flex.justify-around
- if current_member == @member
.flex.justify-around
= link_to edit_member_path(@member) do
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
Edit
= link_to new_story_path() do
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
New Story
= form_tag( destroy_member_session_path , {method: :delete } ) do
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit}
Sign out
- @member.stories.each do |story|
=render "stories/inline" , story: story

View File

@ -1,22 +0,0 @@
= form_for @story do |f|
- if @story.errors.any?
#error_explanation
%h2= "#{pluralize(@story.errors.count, "error")} prohibited this story from being saved:"
%ul
- @story.errors.full_messages.each do |message|
%li= message
.field
= f.label :picture
= f.text_field :picture
.field
= f.label :header
= f.text_field :header
.field
= f.label :text
= f.text_area :text
.field
= f.label :happened
= f.date_field :happened
.actions
= f.submit 'Save'

View File

@ -0,0 +1,12 @@
%section.overflow-hidden.grid.grid-cols-1.m-5.md:m-12.lg:m-20.md:grid-cols-2
%div
= image_for( story , "h-56 w-full object-cover sm:h-full")
.p-8.md:p-12.lg:px-16.lg:py-24
.mx-auto.max-w-xl.text-center
%h2.text-2xl.font-bold.md:text-4xl
= story.header
%h4.text-xl.mt-10.md:text-2xl
= distance_of_time_in_words_to_now story.happened
ago
.mt-8{ prose_classes }
= markdown(story.text)

View File

@ -1,7 +1,20 @@
%h1 Editing story
.grid.grid-cols-3
%div
%div
%h1 Editing story
= form_for @story do |f|
- if @story.errors.any?
#error_explanation
%h2= "#{pluralize(@story.errors.count, "error")} prohibited this story from being saved:"
%ul
- @story.errors.full_messages.each do |message|
%li= message
= render 'form'
= link_to 'Show', @story
\|
= link_to 'Back', stories_path
= f.input :picture , as: :file
= f.input :header
= f.input :text
= f.input :happened , class: "flex"
= f.submit 'Save'
= link_to 'Show', @story
= link_to 'Back', stories_path
%div

View File

@ -1,26 +1,6 @@
%h1 Listing stories
%table
%thead
%tr
%th Picture
%th Header
%th Text
%th Happened
%th
%th
%th
%tbody
- @stories.each do |story|
%tr
%td= story.picture
%td= story.header
%td= story.text
%td= story.happened
%td= link_to 'Show', story
%td= link_to 'Edit', edit_story_path(story)
%td= link_to 'Destroy', story, method: :delete, data: { confirm: 'Are you sure?' }
= paginate @stories
- @stories.each do |story|
= render "inline" , story: story
%br

View File

@ -1,5 +1,20 @@
%h1 New story
= render 'form'
.grid.grid-cols-3
%div
%div
%h1 New story
= form_for @story do |f|
- if @story.errors.any?
#error_explanation
%h2= "#{pluralize(@story.errors.count, "error")} prohibited this story from being saved:"
%ul
- @story.errors.full_messages.each do |message|
%li= message
= link_to 'Back', stories_path
= f.input :picture , as: :file
= f.input :header
= f.input :text
= f.input :happened , class: "flex"
= f.submit 'Save'
= link_to 'Back', stories_path
%div

View File

@ -1,17 +1,4 @@
%p#notice= notice
%p
%b Picture:
= @story.picture
%p
%b Header:
= @story.header
%p
%b Text:
= @story.text
%p
%b Happened:
= @story.happened
= render "inline" , story: @story
= link_to 'Edit', edit_story_path(@story)
\|

View File

@ -1,6 +1,7 @@
class CreateStories < ActiveRecord::Migration[7.0]
def change
create_table :stories do |t|
t.references :member
t.string :picture
t.string :header
t.text :text

2
db/schema.rb generated
View File

@ -47,12 +47,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_11_164425) do
end
create_table "stories", force: :cascade do |t|
t.bigint "member_id"
t.string "picture"
t.string "header"
t.text "text"
t.date "happened"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["member_id"], name: "index_stories_on_member_id"
end
create_table "thredded_categories", force: :cascade do |t|