Class: CargoWiki::ArticlesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CargoWiki::ArticlesController
- Defined in:
- app/controllers/cargo_wiki/articles_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #publish ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 44 def create @article = current_user.articles.published.new(params[:article]) respond_to do |format| if @article.save format.html { redirect_to @article, notice: 'Article was successfully created.' } format.json { render json: @article, status: :created, location: @article } else format.html { render action: "new" } format.json { render json: @article.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 72 def destroy @article = Article.published.find(params[:id]) @article.published = false @article. = "unpublished article" @article.save! respond_to do |format| format.html { redirect_to articles_url } format.json { head :no_content } end end |
#edit ⇒ Object
40 41 42 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 40 def edit @article = Article.published.find(params[:id]) end |
#index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 6 def index if params[:tag_id] @tag = ActsAsTaggableOn::Tag.find(params[:tag_id]) @articles = Article.published.tagged_with(@tag.name).order('updated_at DESC') @unpublished_articles = Article.unpublished.tagged_with(@tag.name).order('updated_at DESC') else @articles = Article.published.order('updated_at DESC') @unpublished_articles = Article.unpublished end respond_to do |format| format.html # index.html.erb format.json { render json: @articles } end end |
#new ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 31 def new @article = current_user.articles.new respond_to do |format| format.html # new.html.erb format.json { render json: @article } end end |
#preview ⇒ Object
96 97 98 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 96 def preview @body = params[:body] end |
#publish ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 84 def publish @article = Article.unpublished.find(params[:id]) @article.published = true @article. = "published article" @article.save! respond_to do |format| format.html { redirect_to articles_url } format.json { head :no_content } end end |
#show ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 22 def show @article = Article.published.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @article } end end |
#update ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/cargo_wiki/articles_controller.rb', line 58 def update @article = Article.published.find(params[:id]) respond_to do |format| if @article.update_attributes(params[:article]) format.html { redirect_to @article, notice: 'Article was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @article.errors, status: :unprocessable_entity } end end end |