Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regenerate articles controller with simple code, remove attr accessib…
…le call and fix deprecation warning
- Loading branch information
1 parent
b4bedbe
commit 1636020
Showing
4 changed files
with
28 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,58 @@ | ||
class ArticlesController < ApplicationController | ||
before_action :set_article, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /articles | ||
# GET /articles.json | ||
def index | ||
@articles = Article.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render :json => @articles } | ||
end | ||
end | ||
|
||
# GET /articles/1 | ||
# GET /articles/1.json | ||
def show | ||
@article = Article.includes(:comments).find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render :json => @article } | ||
end | ||
end | ||
|
||
# GET /articles/new | ||
# GET /articles/new.json | ||
def new | ||
@article = Article.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render :json => @article } | ||
end | ||
end | ||
|
||
# GET /articles/1/edit | ||
def edit | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
# POST /articles | ||
# POST /articles.json | ||
def create | ||
@article = Article.new(params[:article]) | ||
@article = Article.new(article_params) | ||
|
||
respond_to do |format| | ||
if @article.save | ||
format.html { redirect_to @article, :notice => 'Article was successfully created.' } | ||
format.json { render :json => @article, :status => :created, :location => @article } | ||
else | ||
format.html { render :action => "new" } | ||
format.json { render :json => @article.errors, :status => :unprocessable_entity } | ||
end | ||
if @article.save | ||
redirect_to @article, notice: 'Article was successfully created.' | ||
else | ||
render action: 'new' | ||
end | ||
end | ||
|
||
# PUT /articles/1 | ||
# PUT /articles/1.json | ||
# PATCH/PUT /articles/1 | ||
def update | ||
@article = Article.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @article.update_attributes(params[:article]) | ||
format.html { redirect_to @article, :notice => 'Article was successfully updated.' } | ||
format.json { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.json { render :json => @article.errors, :status => :unprocessable_entity } | ||
end | ||
if @article.update(article_params) | ||
redirect_to @article, notice: 'Article was successfully updated.' | ||
else | ||
render action: 'edit' | ||
end | ||
end | ||
|
||
# DELETE /articles/1 | ||
# DELETE /articles/1.json | ||
def destroy | ||
@article = Article.find(params[:id]) | ||
@article.destroy | ||
redirect_to articles_url, notice: 'Article was successfully destroyed.' | ||
end | ||
|
||
respond_to do |format| | ||
format.html { redirect_to articles_url, :notice => 'Article was successfully deleted.' } | ||
format.json { head :ok } | ||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_article | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def article_params | ||
params[:article].permit! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters