Class: ArticlesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ArticlesController
- Defined in:
- lib/generators/mindapp/templates/app/controllers/articles_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #my ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 21 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! end |
#destroy ⇒ Object
50 51 52 53 54 55 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 50 def destroy if current_ma_user.role.upcase.split(',').include?("A") || current_ma_user == @article.user @article.destroy end redirect_to :action=>'index' end |
#edit ⇒ Object
15 16 17 18 19 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 15 def edit @article = Article.find(params[:id]) @page_title = 'Member Login' end |
#index ⇒ Object
5 6 7 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 5 def index @articles = Article.desc(:created_at).page(params[:page]).per(10) end |
#my ⇒ Object
32 33 34 35 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 32 def my @articles = Article.where(user_id: current_ma_user).desc(:created_at).page(params[:page]).per(10) @page_title = 'Member Login' end |
#show ⇒ Object
9 10 11 12 13 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 9 def show (title: @article.title, description: @article.text, keywords: @article.keywords) end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/mindapp/templates/app/controllers/articles_controller.rb', line 37 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"]["article"]["title"], text: $xvars["edit_article"]["article"]["text"], keywords: $xvars["edit_article"]["article"]["keywords"], body: $xvars["edit_article"]["article"]["body"]) end |