adding stories, scaffold
This commit is contained in:
58
app/controllers/stories_controller.rb
Normal file
58
app/controllers/stories_controller.rb
Normal file
@ -0,0 +1,58 @@
|
||||
class StoriesController < ApplicationController
|
||||
before_action :set_story, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /stories
|
||||
def index
|
||||
@stories = Story.all
|
||||
end
|
||||
|
||||
# GET /stories/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /stories/new
|
||||
def new
|
||||
@story = Story.new
|
||||
end
|
||||
|
||||
# GET /stories/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /stories
|
||||
def create
|
||||
@story = Story.new(story_params)
|
||||
|
||||
if @story.save
|
||||
redirect_to @story, notice: "Story was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /stories/1
|
||||
def update
|
||||
if @story.update(story_params)
|
||||
redirect_to @story, notice: "Story was successfully updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /stories/1
|
||||
def destroy
|
||||
@story.destroy
|
||||
redirect_to stories_url, notice: "Story was successfully destroyed."
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_story
|
||||
@story = Story.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def story_params
|
||||
params.require(:story).permit(:picture, :header, :text, :happened)
|
||||
end
|
||||
end
|
2
app/helpers/stories_helper.rb
Normal file
2
app/helpers/stories_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module StoriesHelper
|
||||
end
|
2
app/models/story.rb
Normal file
2
app/models/story.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Story < ApplicationRecord
|
||||
end
|
@ -1,14 +0,0 @@
|
||||
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
|
||||
<% if blob.representable? %>
|
||||
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
|
||||
<% end %>
|
||||
|
||||
<figcaption class="attachment__caption">
|
||||
<% if caption = blob.try(:caption) %>
|
||||
<%= caption %>
|
||||
<% else %>
|
||||
<span class="attachment__name"><%= blob.filename %></span>
|
||||
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
|
||||
<% end %>
|
||||
</figcaption>
|
||||
</figure>
|
@ -1,14 +1,12 @@
|
||||
= paginate @members
|
||||
.flex.justify-center
|
||||
|
||||
%h1 Listing members
|
||||
= paginate @members
|
||||
|
||||
.grid.grid-cols-4
|
||||
- @members.each do |member|
|
||||
.fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10
|
||||
= image_for( member , class: "h-60 w-full object-cover")
|
||||
%h3.p-5.text-2xl.bg-gray-100.text-black.font-bold.text-center= member.name
|
||||
%div.h-full
|
||||
.p-5.text-center
|
||||
.m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes }
|
||||
= markdown(member.bio)
|
||||
.grid.grid-cols-4
|
||||
- @members.each do |member|
|
||||
.fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10
|
||||
= image_for( member , class: "h-60 w-full object-cover")
|
||||
%h3.p-5.text-2xl.bg-gray-100.text-black.font-bold.text-center= member.name
|
||||
%div.h-full
|
||||
.p-5.text-center
|
||||
.m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes }
|
||||
= markdown(member.bio)
|
||||
|
22
app/views/stories/_form.html.haml
Normal file
22
app/views/stories/_form.html.haml
Normal file
@ -0,0 +1,22 @@
|
||||
= 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'
|
7
app/views/stories/edit.html.haml
Normal file
7
app/views/stories/edit.html.haml
Normal file
@ -0,0 +1,7 @@
|
||||
%h1 Editing story
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Show', @story
|
||||
\|
|
||||
= link_to 'Back', stories_path
|
27
app/views/stories/index.html.haml
Normal file
27
app/views/stories/index.html.haml
Normal file
@ -0,0 +1,27 @@
|
||||
%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?' }
|
||||
|
||||
%br
|
||||
|
||||
= link_to 'New Story', new_story_path
|
5
app/views/stories/new.html.haml
Normal file
5
app/views/stories/new.html.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%h1 New story
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', stories_path
|
18
app/views/stories/show.html.haml
Normal file
18
app/views/stories/show.html.haml
Normal file
@ -0,0 +1,18 @@
|
||||
%p#notice= notice
|
||||
|
||||
%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 'Back', stories_path
|
Reference in New Issue
Block a user