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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,11 +17,19 @@
%svg.inline-block.w-3.ml-2{:fill => "currentColor", :viewbox => "0 0 12 12"} %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"} %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"}
- if current_member == @member
.flex.justify-around .flex.justify-around
= link_to edit_member_path(@member) do = 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 %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
Edit 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 = 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} %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 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 @@
.grid.grid-cols-3
%div
%div
%h1 Editing story %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' = 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 'Show', @story
\|
= link_to 'Back', stories_path = link_to 'Back', stories_path
%div

View File

@ -1,26 +1,6 @@
%h1 Listing stories = paginate @stories
%table
%thead
%tr
%th Picture
%th Header
%th Text
%th Happened
%th
%th
%th
%tbody
- @stories.each do |story| - @stories.each do |story|
%tr = render "inline" , story: story
%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?' }
%br %br

View File

@ -1,5 +1,20 @@
.grid.grid-cols-3
%div
%div
%h1 New story %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
= render 'form' = f.input :picture , as: :file
= f.input :header
= f.input :text
= f.input :happened , class: "flex"
= f.submit 'Save'
= link_to 'Back', stories_path = link_to 'Back', stories_path
%div

View File

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

View File

@ -1,6 +1,7 @@
class CreateStories < ActiveRecord::Migration[7.0] class CreateStories < ActiveRecord::Migration[7.0]
def change def change
create_table :stories do |t| create_table :stories do |t|
t.references :member
t.string :picture t.string :picture
t.string :header t.string :header
t.text :text 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 end
create_table "stories", force: :cascade do |t| create_table "stories", force: :cascade do |t|
t.bigint "member_id"
t.string "picture" t.string "picture"
t.string "header" t.string "header"
t.text "text" t.text "text"
t.date "happened" t.date "happened"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["member_id"], name: "index_stories_on_member_id"
end end
create_table "thredded_categories", force: :cascade do |t| create_table "thredded_categories", force: :cascade do |t|