residency/app/controllers/stories_controller.rb

56 lines
1.1 KiB
Ruby
Raw Normal View History

2023-01-11 17:48:06 +01:00
class StoriesController < ApplicationController
before_action :set_story, only: %i[ show edit update destroy ]
def index
2023-01-23 23:22:29 +01:00
@q = Story.ransack(params[:q])
@q.sorts = 'created_at desc' if @q.sorts.empty?
@stories = @q.result(distinct: true).page( params[:page])
2023-01-11 17:48:06 +01:00
end
def show
end
def new
@story = Story.new
end
def edit
2023-01-15 21:00:26 +01:00
authorize @story
2023-01-11 17:48:06 +01:00
end
def create
@story = Story.new(story_params)
2023-01-11 19:52:58 +01:00
@story.member = current_member
2023-01-11 17:48:06 +01:00
if @story.save
redirect_to @story, notice: "Story was successfully created."
else
render :new, status: :unprocessable_entity
end
end
def update
2023-01-22 12:17:27 +01:00
authorize @story
2023-01-11 17:48:06 +01:00
if @story.update(story_params)
redirect_to @story, notice: "Story was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
def destroy
2023-01-22 12:17:27 +01:00
authorize @story
2023-01-11 17:48:06 +01:00
@story.destroy
redirect_to stories_url, notice: "Story was successfully destroyed."
end
private
def set_story
@story = Story.find(params[:id])
end
def story_params
2023-01-25 21:15:54 +01:00
params.require(:story).permit(:picture,:picture_cache, :header, :text, :happened)
2023-01-11 17:48:06 +01:00
end
end