Class: NewsPostsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/news_posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /news_posts POST /news_posts.json



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/news_posts_controller.rb', line 49

def create
  @news_post = NewsPost.new(news_post_params)
  @news_post.user = current_user

  respond_to do |format|
    if @news_post.save
      format.html { redirect_to(@news_post, notice: t('controller.successfully_created', model: t('activerecord.models.news_post'))) }
      format.json { render json: @news_post, status: :created, location: @news_post }
    else
      prepare_options
      format.html { render action: "new" }
      format.json { render json: @news_post.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /news_posts/1 DELETE /news_posts/1.json



87
88
89
90
91
92
93
94
# File 'app/controllers/news_posts_controller.rb', line 87

def destroy
  @news_post.destroy

  respond_to do |format|
    format.html { redirect_to(news_posts_url) }
    format.json { head :no_content }
  end
end

#editObject

GET /news_posts/1/edit



44
45
# File 'app/controllers/news_posts_controller.rb', line 44

def edit
end

#indexObject

GET /news_posts GET /news_posts.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/news_posts_controller.rb', line 8

def index
  if current_user.try(:has_role?, 'Librarian')
    @news_posts = NewsPost.page(params[:page])
  else
    @news_posts = NewsPost.published.page(params[:page])
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @news_posts }
    format.rss  { render layout: false }
    format.atom
  end
end

#newObject

GET /news_posts/new GET /news_posts/new.json



34
35
36
37
38
39
40
41
# File 'app/controllers/news_posts_controller.rb', line 34

def new
  @news_post = NewsPost.new

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

#showObject

GET /news_posts/1 GET /news_posts/1.json



25
26
27
28
29
30
# File 'app/controllers/news_posts_controller.rb', line 25

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

#updateObject

PUT /news_posts/1 PUT /news_posts/1.json



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/news_posts_controller.rb', line 67

def update
  if params[:move]
    move_position(@news_post, params[:move])
    return
  end

  respond_to do |format|
    if @news_post.update_attributes(news_post_params)
      format.html { redirect_to(@news_post, notice: t('controller.successfully_updated', model: t('activerecord.models.news_post'))) }
      format.json { head :no_content }
    else
      prepare_options
      format.html { render action: "edit" }
      format.json { render json: @news_post.errors, status: :unprocessable_entity }
    end
  end
end