56 lines
1.1 KiB
Ruby
56 lines
1.1 KiB
Ruby
class StoriesController < ApplicationController
|
|
before_action :set_story, only: %i[ show edit update destroy ]
|
|
|
|
def index
|
|
@q = Story.ransack(params[:q])
|
|
@q.sorts = 'created_at desc' if @q.sorts.empty?
|
|
@stories = @q.result(distinct: true).page( params[:page])
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
@story = Story.new
|
|
end
|
|
|
|
def edit
|
|
authorize @story
|
|
end
|
|
|
|
def create
|
|
@story = Story.new(story_params)
|
|
@story.member = current_member
|
|
|
|
if @story.save
|
|
redirect_to @story, notice: "Story was successfully created."
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update
|
|
authorize @story
|
|
if @story.update(story_params)
|
|
redirect_to @story, notice: "Story was successfully updated."
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
authorize @story
|
|
@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
|
|
params.require(:story).permit(:picture,:picture_cache, :header, :text, :happened)
|
|
end
|
|
end
|