75 lines
1.1 KiB
Ruby
75 lines
1.1 KiB
Ruby
|
|
class ArticlesController < ApplicationController
|
||
|
|
before_action :authenticate_user!, only: [:new, :edit, :update, :create]
|
||
|
|
allow_unauthenticated_access(only: %i[index show])
|
||
|
|
|
||
|
|
def feed
|
||
|
|
@articles = Article.order(created_at: :asc)
|
||
|
|
response.headers['Content-Type'] = 'application/rss+xml'
|
||
|
|
render 'feed', formats: :xml
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def index
|
||
|
|
@articles = Article.order(created_at: :desc)
|
||
|
|
@members = Member.all
|
||
|
|
@blogs = Blog.all
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def show
|
||
|
|
@article = Article.find(params[:id])
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def new
|
||
|
|
@article = Article.new
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def create
|
||
|
|
@article = Article.new(article_params)
|
||
|
|
if @article.save
|
||
|
|
redirect_to @article
|
||
|
|
else
|
||
|
|
render 'new'
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def edit
|
||
|
|
@article = Article.find(params[:id])
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def update
|
||
|
|
@article = Article.find(params[:id])
|
||
|
|
if @article.update(article_params)
|
||
|
|
redirect_to @article
|
||
|
|
else
|
||
|
|
render :edit
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
def destroy
|
||
|
|
@article = Article.find(params[:id])
|
||
|
|
@article.destroy
|
||
|
|
redirect_to articles_path
|
||
|
|
end
|
||
|
|
|
||
|
|
private
|
||
|
|
|
||
|
|
|
||
|
|
def article_params
|
||
|
|
params.require(:article).permit(:title, :text, :mood, :music, :icon_image)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|