Class: ArticlesController

Inherits:
ApplicationController show all
Defined in:
lib/generators/jinda/templates/app/controllers/articles_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#prepare_meta_tags

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 20

def create
  @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!

# 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
  
end

#destroyObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 64

def destroy
# duplicated from jinda_controller
# Expected to use in jinda)controller
  #
  current_ma_user = Jinda::User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
  if Rails.env.test? #Temp solution until fix test of current_ma_user
    current_ma_user = $xvars["current_ma_user"]
    #current_ma_user = @article.user
  end
  if current_ma_user.role.upcase.split(',').include?("A") || current_ma_user == @article.user
    @article.destroy
  end
    #redirect_to :action=>'index'
    redirect_to :action=>'my'
end

#editObject



15
16
17
18
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 15

def edit
  @article = Article.find(params[:id])
  @page_title       = 'Member Login'
end

#indexObject



5
6
7
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 5

def index
   @articles = Article.desc(:created_at).page(params[:page]).per(10)
end

#myObject



43
44
45
46
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 43

def my
  @articles = Article.where(user_id: current_ma_user).desc(:created_at).page(params[:page]).per(10)
  @page_title       = 'Member Login'
end

#showObject



9
10
11
12
13
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 9

def show 
  prepare_meta_tags(title: @article.title,
                    description: @article.text,
                    keywords: @article.keywords)
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generators/jinda/templates/app/controllers/articles_controller.rb', line 48

def update
  # $xvars["select_article"] and $xvars["edit_article"]
  # These are variables.
  # 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"],
                  keywords: $xvars["edit_article"]["keywords"],
                  body: $xvars["edit_article"]["body"]
                )
  # redirect_to @article
# comment out to use jinda_controller end_action
end