Class: ArticlesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ArticlesController
- Defined in:
- lib/generators/jinda/templates/app/controllers/jinda_org/articles_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #j_update ⇒ Object
- #my ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/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 |
#destroy ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/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 |
#edit ⇒ Object
26 27 28 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/articles_controller.rb', line 26 def edit @page_title = 'Edit Article' end |
#index ⇒ Object
6 7 8 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/articles_controller.rb', line 6 def index # before_action end |
#j_update ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/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 |
#my ⇒ Object
10 11 12 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/articles_controller.rb', line 10 def my # before_action end |
#show ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/articles_controller.rb', line 14 def show @article = Article.find(article_params) @commentable = @article @comments = @commentable.comments.desc(:created_at).page(params[:page]).per(10) @user = User.find(@article.user_id) @show = Hash.new @show = {:article => @article, :comments => @comments, :user => @user} (title: @article.title, description: @article.text, keywords: @article.keywords) end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/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 |