Class: Ems::ArticlesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ems/articles_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#createObject

POST /articles POST /articles.json



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/ems/articles_controller.rb', line 48

def create
  @article = Article.new(params[:article])

  respond_to do |format|
    if @article.save
      format.html { redirect_to edit_category_article_path(@article.category, @article), notice: 'Article was successfully created.' }
      format.json { render json: @article, status: :created, location: @article }
    else
      format.html { render action: "new", :category_id => @article.category, :id => @article }
      format.json { render json: @article.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /articles/1 DELETE /articles/1.json



80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/ems/articles_controller.rb', line 80

def destroy
  @article = Article.find(params[:id])
  category = @article.category
  @article.destroy

  respond_to do |format|
    format.html { redirect_to category_articles_path(category), notice: 'Article was successfully deleted.' }
    format.json { head :no_content }
  end
end

#editObject

GET /articles/1/edit



41
42
43
44
# File 'app/controllers/ems/articles_controller.rb', line 41

def edit
  @article = Article.find(params[:id])
  @article.assets.build
end

#indexObject

GET /articles GET /articles.json



7
8
9
10
11
12
13
14
# File 'app/controllers/ems/articles_controller.rb', line 7

def index
  @articles = Article.all

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @articles }
  end
end

#newObject

GET /articles/new GET /articles/new.json



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

def new
  @article = Article.new(:category => Category.find(params[:category_id]))
  @article.assets.build
  @article.category = Category.find params[:category_id]

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @article }
  end
end

#showObject

GET /articles/1 GET /articles/1.json



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

def show
  @article = Article.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @article }
  end
end

#updateObject

PUT /articles/1 PUT /articles/1.json



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/ems/articles_controller.rb', line 64

def update
  @article = Article.find(params[:id])

  respond_to do |format|
    if @article.update_attributes(params[:article])
      format.html { redirect_to edit_category_article_path(@article.category, @article), notice: 'Article was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit", :category_id => @article.category, :id => @article }
      format.json { render json: @article.errors, status: :unprocessable_entity }
    end
  end
end