Class: NewsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- NewsController
- Defined in:
- app/controllers/news_controller.rb
Overview
This controller scopes to News::Project classes for show and index.
See the related Administration controller for Administration news scoping of show and index.
Create/udpate scoping to Administrators is handled in the model.
Direct Known Subclasses
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#api_index ⇒ Object
Serves only current blog_posts at the moment.
-
#api_show ⇒ Object
Serves only current blog_posts at the moment.
-
#create ⇒ Object
POST /news or /news.json.
-
#destroy ⇒ Object
DELETE /news/1 or /news/1.json.
-
#edit ⇒ Object
GET /news/1/edit.
-
#index ⇒ Object
GET /news or /news.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /news/new.
- #news_params ⇒ Object private
- #set_news ⇒ Object private
-
#show ⇒ Object
GET /news/1 or /news/1.json.
- #types ⇒ Object
-
#update ⇒ Object
PATCH/PUT /news/1 or /news/1.json.
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#cumulative_gb_per_year, #cumulative_projects_created_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_initials, #project_link, #project_login_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #taxonworks_classification, #week_in_review_graphs
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_index ⇒ Object
Serves only current blog_posts at the moment
31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/news_controller.rb', line 31 def api_index @news = News::Project::BlogPost .where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per]) .order(:display_start, :created_at) render '/news/api/v1/index' end |
#api_show ⇒ Object
Serves only current blog_posts at the moment
42 43 44 45 |
# File 'app/controllers/news_controller.rb', line 42 def api_show @news = News::Project::BlogPost.find(params[:id]) render '/news/api/v1/show' end |
#create ⇒ Object
POST /news or /news.json
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/news_controller.rb', line 61 def create @news = News.new(news_params) respond_to do |format| if @news.save format.html { redirect_to @news.becomes(@news.class.base_class), notice: 'News was successfully created.' } format.json { render :show, status: :created, location: @news. } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @news.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /news/1 or /news/1.json
89 90 91 92 93 94 95 96 |
# File 'app/controllers/news_controller.rb', line 89 def destroy @news.destroy! respond_to do |format| format.html { redirect_to news_index_path, notice: 'News was successfully destroyed.', status: :see_other } format.json { head :no_content } end end |
#edit ⇒ Object
GET /news/1/edit
57 58 |
# File 'app/controllers/news_controller.rb', line 57 def edit end |
#index ⇒ Object
GET /news or /news.json
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/news_controller.rb', line 14 def index respond_to do |format| # We use the "Newspaper" for displaying news format.html do redirect_to :browse_news_task and return end format.json { @news = News::Project.where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per]) .order(created_at: :desc) } end end |
#list ⇒ Object
98 99 100 |
# File 'app/controllers/news_controller.rb', line 98 def list @news = News.where(project_id: sessions_current_project_id).page(params[:page]).per(params[:per]) end |
#new ⇒ Object
GET /news/new
52 53 54 |
# File 'app/controllers/news_controller.rb', line 52 def new @news = News.new end |
#news_params ⇒ Object (private)
116 117 118 |
# File 'app/controllers/news_controller.rb', line 116 def news_params params.require(:news).permit(:type, :title, :body, :display_start, :display_end, :is_public) end |
#set_news ⇒ Object (private)
112 113 114 |
# File 'app/controllers/news_controller.rb', line 112 def set_news @news = News.find(params[:id]) end |
#show ⇒ Object
GET /news/1 or /news/1.json
48 49 |
# File 'app/controllers/news_controller.rb', line 48 def show end |
#types ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'app/controllers/news_controller.rb', line 102 def types types = { project: News::PROJECT_TYPES.keys, administration: News::ADMINISTRATION_TYPES.keys } render json: types end |
#update ⇒ Object
PATCH/PUT /news/1 or /news/1.json
76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/news_controller.rb', line 76 def update respond_to do |format| if @news.update(news_params) format.html { redirect_to @news., notice: 'News was successfully updated.', status: :see_other } format.json { render :show, status: :ok, location: @news. } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @news.errors, status: :unprocessable_entity } end end end |