Class: NewsPostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- NewsPostsController
- Defined in:
- app/controllers/news_posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /news_posts POST /news_posts.json.
-
#destroy ⇒ Object
DELETE /news_posts/1 DELETE /news_posts/1.json.
-
#edit ⇒ Object
GET /news_posts/1/edit.
-
#index ⇒ Object
GET /news_posts GET /news_posts.json.
-
#new ⇒ Object
GET /news_posts/new GET /news_posts/new.json.
-
#show ⇒ Object
GET /news_posts/1 GET /news_posts/1.json.
-
#update ⇒ Object
PUT /news_posts/1 PUT /news_posts/1.json.
Instance Method Details
#create ⇒ Object
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 format.html { render action: "new" } format.json { render json: @news_post.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
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 |
#edit ⇒ Object
GET /news_posts/1/edit
44 45 |
# File 'app/controllers/news_posts_controller.rb', line 44 def edit end |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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 format.html { render action: "edit" } format.json { render json: @news_post.errors, status: :unprocessable_entity } end end end |