lib/generators/jinda/templates/app/controllers/articles_controller.rb in jinda-0.2.3 vs lib/generators/jinda/templates/app/controllers/articles_controller.rb in jinda-0.2.4
- old
+ new
@@ -1,7 +1,8 @@
class ArticlesController < ApplicationController
- before_action :load_article, only: [:show, :destroy]
+ before_action :load_article, only: [:show,]
+ before_action :load_edit_article, only: [:edit, :destroy]
before_action :load_comments, only: [:show]
def index
@articles = Article.desc(:created_at).page(params[:page]).per(10)
end
@@ -23,23 +24,11 @@
text: $xvars["form_article"]["text"],
keywords: $xvars["form_article"]["keywords"],
body: $xvars["form_article"]["body"],
user_id: $xvars["user_id"])
@article.save!
-
- # comment out to use jinda_controller end_action
- # redirect_to @article
- # if @article.save!
- # # format.html { redirect_to @article, notice: 'Sample was successfully created.' }
- # format.html { redirect_to @article }
- # format.json { render :show, status: :created, location: @article }
- # end
- # else
- # format.html { render :new }
- # format.json { render json: @article.errors, status: :unprocessable_entity }
- # end
-
+ refresh_to
end
def my
@articles = Article.where(user_id: current_ma_user).desc(:created_at).page(params[:page]).per(10)
@page_title = 'Member Login'
@@ -51,16 +40,14 @@
# They contain everything that we get their forms select_article and edit_article
article_id = $xvars["select_article"] ? $xvars["select_article"]["title"] : $xvars["p"]["article_id"]
@article = Article.find(article_id)
@article.update(title: $xvars["edit_article"]["title"],
- text: $xvars["edit_article"]["text"],
+ tenxt: $xvars["edit_article"]["text"],
keywords: $xvars["edit_article"]["keywords"],
body: $xvars["edit_article"]["body"]
)
- # redirect_to @article
- # comment out to use jinda_controller end_action
end
def destroy
# duplicated from jinda_controller
# Expected to use in jinda)controller
@@ -77,11 +64,15 @@
redirect_to :action=>'my'
end
private
- def load_article
+ def load_edit_article
@article = Article.find(params.require(:article_id))
+ end
+
+ def load_article
+ @article = Article.find(params.permit(:id))
end
def load_comments
@comments = @article.comments.find_all
end