first commit
This commit is contained in:
2
app/controllers/application_controller.rb
Normal file
2
app/controllers/application_controller.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
end
|
51
app/controllers/articles_controller.rb
Normal file
51
app/controllers/articles_controller.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
class ArticlesController < ApplicationController
|
||||
http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show]
|
||||
|
||||
def index
|
||||
@articles = Article.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, status: :unprocessable_entity
|
||||
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, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@article = Article.find(params[:id])
|
||||
@article.destroy
|
||||
|
||||
redirect_to root_path, status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
def article_params
|
||||
params.require(:article).permit(:title, :body, :status)
|
||||
end
|
||||
end
|
21
app/controllers/comments_controller.rb
Normal file
21
app/controllers/comments_controller.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class CommentsController < ApplicationController
|
||||
http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy
|
||||
|
||||
def create
|
||||
@article = Article.find(params[:article_id])
|
||||
@comment = @article.comments.create(comment_params)
|
||||
redirect_to article_path(@article)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@article = Article.find(params[:article_id])
|
||||
@comment = @article.comments.find(params[:id])
|
||||
comment.destroy
|
||||
redirect_to article_path(@article), status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
def comment_params
|
||||
params.require(:comment).permit(:commenter, :body, :status)
|
||||
end
|
||||
end
|
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
Reference in New Issue
Block a user