diff --git a/app/controllers/admins/topic/glcc_news_controller.rb b/app/controllers/admins/topic/glcc_news_controller.rb new file mode 100644 index 000000000..3c1769e5f --- /dev/null +++ b/app/controllers/admins/topic/glcc_news_controller.rb @@ -0,0 +1,57 @@ +class Admins::Topic::GlccNewsController < Admins::Topic::BaseController + before_action :find_glcc, only: [:edit, :update, :destroy] + + def index + q = ::Topic::GlccNews.ransack(title_cont: params[:search]) + glcc_news = q.result(distinct: true) + @glcc_news = paginate(glcc_news) + end + + def new + @glcc = ::Topic::GlccNews.new + end + + def create + @glcc = ::Topic::GlccNews.new(glcc_params) + if @glcc.save + redirect_to admins_topic_glcc_news_index_path + flash[:success] = "新增新闻稿成功" + else + redirect_to admins_topic_glcc_news_index_path + flash[:danger] = "新增新闻稿失败" + end + end + + def edit + end + + def update + @glcc.attributes = glcc_params + if @glcc.save + redirect_to admins_topic_glcc_news_index_path + flash[:success] = "更新新闻稿成功" + else + redirect_to admins_topic_glcc_news_index_path + flash[:danger] = "更新新闻稿失败" + end + end + + def destroy + if @glcc.destroy + redirect_to admins_topic_glcc_news_index_path + flash[:success] = "删除新闻稿成功" + else + redirect_to admins_topic_glcc_news_index_path + flash[:danger] = "删除新闻稿失败" + end + end + + private + def find_glcc + @glcc = ::Topic::GlccNews.find_by_id(params[:id]) + end + + def glcc_params + params.require(:topic_glcc_news).permit(:title, :uuid, :url, :order_index) + end +end \ No newline at end of file diff --git a/app/models/topic.rb b/app/models/topic.rb index 13bf7b5bd..e464859ec 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -35,6 +35,8 @@ class Topic < ApplicationRecord 'Topic::ExcellentProject' when 'experience_forum' 'Topic::ExperienceForum' + when "glcc_news" + 'Topic::GlccNews' when 'pinned_forum' 'Topic::PinnedForum' end diff --git a/app/models/topic/glcc_news.rb b/app/models/topic/glcc_news.rb new file mode 100644 index 000000000..6b707bf07 --- /dev/null +++ b/app/models/topic/glcc_news.rb @@ -0,0 +1,17 @@ +# == Schema Information +# +# Table name: topics +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# uuid :integer +# image_url :string(255) +# url :string(255) +# order_index :integer +# + +# GLCC 新闻稿 +class Topic::GlccNews < Topic + +end \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 3e659395a..055988731 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -42,7 +42,11 @@
序号 | +标题 | +跳转地址 | +帖子ID | +排序等级 | +操作 | +
---|---|---|---|---|---|
<%= list_index_no((params[:page] || 1).to_i, index) %> | +<%= news.title %> | +<%= news.url %> | +<%= news.uuid %> | +<%= news.order_index %> | ++ <%= link_to "编辑", edit_admins_topic_glcc_news_path(news), remote: true, class: "action" %> + <%= link_to "删除", admins_topic_glcc_news_path(news), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %> + | +