first gallery version
This commit is contained in:
55
app/controllers/pictures_controller.rb
Normal file
55
app/controllers/pictures_controller.rb
Normal file
@ -0,0 +1,55 @@
|
||||
class PicturesController < ApplicationController
|
||||
before_action :set_picture, only: %i[ show edit update destroy ]
|
||||
|
||||
def index
|
||||
@q = Picture.ransack(params[:q])
|
||||
@q.sorts = 'created_at desc' if @q.sorts.empty?
|
||||
@pictures = @q.result(distinct: true).page( params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@picture = Picture.new
|
||||
end
|
||||
|
||||
def edit
|
||||
authorize @picture
|
||||
end
|
||||
|
||||
def create
|
||||
@picture = Picture.new(picture_params)
|
||||
@picture.member = current_member
|
||||
|
||||
if @picture.save
|
||||
redirect_to @picture, notice: "Picture was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
authorize @picture
|
||||
if @picture.update(picture_params)
|
||||
redirect_to @picture, notice: "Picture was successfully updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize @picture
|
||||
@picture.destroy
|
||||
redirect_to pictures_url, notice: "Picture was successfully destroyed."
|
||||
end
|
||||
|
||||
private
|
||||
def set_picture
|
||||
@picture = Picture.find(params[:id])
|
||||
end
|
||||
|
||||
def picture_params
|
||||
params.require(:picture).permit(:picture,:picture_cache ,:text, :member_id)
|
||||
end
|
||||
end
|
@ -45,13 +45,11 @@ class StoriesController < ApplicationController
|
||||
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)
|
||||
params.require(:story).permit(:picture,:picture_cache, :header, :text, :happened)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user