Class: Jinda::ArticlesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/jindra_engine/articles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/jindra_engine/articles_controller.rb', line 30

def create
  # Use Jinda $xvars
  @article = Article.new(
    title: $xvars["form_article"]["title"],
    text: $xvars["form_article"]["text"],
    keywords: $xvars["form_article"]["keywords"],
    body: $xvars["form_article"]["body"],
    user_id: $xvars["user_id"])
  @article.save!
end

#destroyObject



63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/jindra_engine/articles_controller.rb', line 63

def destroy
  # Use Rails 
  # before_action

  if current_admin? || current_ma_user == @article.user
    @article.destroy
  end

  action = (current_admin? ? 'index' : 'my') 
  redirect_to :action=> (current_admin? ? 'index' : 'my') 
end

#editObject



26
27
28
# File 'app/controllers/jindra_engine/articles_controller.rb', line 26

def edit
  @page_title       = 'Edit Article'
end

#indexObject



10
11
12
# File 'app/controllers/jindra_engine/articles_controller.rb', line 10

def index
  # before_action
end

#j_updateObject



52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/jindra_engine/articles_controller.rb', line 52

def j_update
  # Use Jinda $xvars
  @article_id = $xvars["select_article"] ? $xvars["select_article"]["title"] : $xvars["p"]["article_id"]
  @article = Article.find_by :id => @article_id
  @article.update(title: $xvars["edit_article"]["article"]["title"],
                  text: $xvars["edit_article"]["article"]["text"],
                  keywords: $xvars["edit_article"]["article"]["keywords"],
                  body: $xvars["edit_article"]["article"]["body"]
                 )
end

#myObject



14
15
16
# File 'app/controllers/jindra_engine/articles_controller.rb', line 14

def my
  # before_action
end

#showObject



18
19
20
21
22
23
24
# File 'app/controllers/jindra_engine/articles_controller.rb', line 18

def show
  @article = Article.find(params[:article_id])
  @comments = @article.comments.desc(:created_at).page(params[:page]).per(10)
  prepare_meta_tags(title: @article.title,
                    description: @article.text,
                    keywords: @article.keywords)
end

#updateObject



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/jindra_engine/articles_controller.rb', line 41

def update
  @article = Article.find(params[:id])
  @article.update(
    title: params["article"]["title"],
    text: params["article"]["text"],
    keywords: params["article"]["keywords"],
    body: params["article"]["body"]
  )
  redirect_to :action=> 'show', :article_id => @article.id
end