diff --git a/README.md b/README.md
index 1c56937f0..6b39d4d02 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,8 @@ simple_intruduce(requires): String, 新闻简介
remote_url(requires): String, 新闻访问地址
+platform(requires): String, 该条数据的来源{educoder | trusite | ihub | gcc | openi |toschina | military | jiaotong_university}; 如educoder说明是来源educoder平台
+
返回值
```
diff --git a/app/api/mobile/apis/homes.rb b/app/api/mobile/apis/homes.rb
index 18b914a06..41baff9dd 100644
--- a/app/api/mobile/apis/homes.rb
+++ b/app/api/mobile/apis/homes.rb
@@ -41,6 +41,7 @@ module Mobile
requires :title, type: String
requires :simple_intruduce, type: String
requires :remote_url, type: String, regexp: Home::REG_URL_FORMAT
+ requires :platform, type: String, desc: "platform requires." , values: DynamicNew::PLATFORMS
end
put 'sync_news' do
authenticate_token!
@@ -50,7 +51,8 @@ module Mobile
remote_url: params[:remote_url],
category_id: params[:category_id],
content: params[:content],
- cover_remote_url: params[:cover_remote_url]
+ cover_remote_url: params[:cover_remote_url],
+ platform: params[:platform]
}
begin
DynamicNewsService.new.sync(news_params)
diff --git a/app/controllers/dynamic_news_controller.rb b/app/controllers/dynamic_news_controller.rb
index dc70dcdfd..ea47e15db 100644
--- a/app/controllers/dynamic_news_controller.rb
+++ b/app/controllers/dynamic_news_controller.rb
@@ -1,14 +1,14 @@
class DynamicNewsController < ApplicationController
- layout 'admin', only: [:new, :index, :destroy]
+ layout 'admin', only: [:new, :destroy, :edit]
- before_filter :require_admin, :only => [:new, :create, :destroy]
- before_filter :find_dynamic_new, :only => [:show, :destroy]
+ before_filter :require_admin, :except => [:index, :show]
+ before_filter :find_dynamic_new, :only => [:destroy, :edit, :update]
def index
-
end
def new
+ @category_id = params[:category_id] || 0
@dynamic_new = DynamicNew.new
end
@@ -16,20 +16,22 @@ class DynamicNewsController < ApplicationController
tmp_file = params[:cover]
@dynamic_new = DynamicNew.new(params[:dynamic_new])
begin
- ActiveRecord::Base.transaction do
- identity = SecureRandom.uuid
- unless tmp_file.nil?
- File.open(Rails.root.join('public', 'images', 'dynamic_new', identity.to_s+'.png'), 'wb') do |file|
- file.write(tmp_file.read)
- end
- @dynamic_new.cover_remote_url = "/images/dynamic_new/#{identity}.png"
+ identity = SecureRandom.uuid
+ unless tmp_file.nil?
+ File.open(Rails.root.join('public', 'images', 'dynamic_new', identity.to_s+'.png'), 'wb') do |file|
+ file.write(tmp_file.read)
end
- # TODO: 如下警告信息导致值写不进库
- # WARNING: Can't mass-assign protected attributes: simple_intruduce,
- @dynamic_new.simple_intruduce = params[:dynamic_new][:simple_intruduce]
- @dynamic_new.save
+ @dynamic_new.cover_remote_url = "/images/dynamic_new/#{identity}.png"
end
- redirect_to admin_dynamic_news_path
+ # TODO: 如下警告信息导致值写不进库
+ # WARNING: Can't mass-assign protected attributes: simple_intruduce,
+ @dynamic_new.simple_intruduce = params[:dynamic_new][:simple_intruduce]
+ if @dynamic_new.save!
+ redirect_to admin_dynamic_news_path
+ else
+ render :action => 'new'
+ end
+
rescue => e
logger.info e
render 'new'
@@ -41,6 +43,14 @@ class DynamicNewsController < ApplicationController
redirect_to admin_dynamic_news_path
end
+ def edit
+ end
+
+ def update
+ @dynamic_new.update_attributes!(params[:dynamic_new])
+ redirect_to admin_dynamic_news_path
+ end
+
def show
end
diff --git a/app/models/dynamic_new.rb b/app/models/dynamic_new.rb
index 732735cb9..4ede12d31 100644
--- a/app/models/dynamic_new.rb
+++ b/app/models/dynamic_new.rb
@@ -1,4 +1,5 @@
class DynamicNew < ActiveRecord::Base
+ PLATFORMS = %w(educoder trusite ihub gcc openi toschina military jiaotong_university)
belongs_to :category
validates_presence_of :title, :simple_intruduce, :category_id
diff --git a/app/views/admin/_dynamic_news.html.erb b/app/views/admin/_dynamic_news.html.erb
index 595377f2a..8771bb1b8 100644
--- a/app/views/admin/_dynamic_news.html.erb
+++ b/app/views/admin/_dynamic_news.html.erb
@@ -54,8 +54,8 @@
<%= format_time(dynamic_new.created_at) %>
- <%= link_to("修改", upload_logo_school_path(dynamic_new.id,:school_name => @school_name), :class => 'icon icon-copy') %>
- <%= link_to(l(:button_delete), dynamic_news_path(dynamic_new), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
+ <%= link_to("修改", edit_dynamic_news_path(dynamic_new), :class => 'icon icon-copy') %>
+ <%= link_to(l(:button_delete), dynamic_news_path(dynamic_new), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
|
<% end %>
@@ -64,12 +64,3 @@
-
-
-
diff --git a/app/views/dynamic_news/_form.html.erb b/app/views/dynamic_news/_form.html.erb
new file mode 100644
index 000000000..0e58e0cea
--- /dev/null
+++ b/app/views/dynamic_news/_form.html.erb
@@ -0,0 +1,70 @@
+<%= form_for(@dynamic_new, :url=> { :action => params[:action] == 'new'? :create : :update }, :html => {:id =>'system_messages-form',:multipart => true }) do |f| %>
+
+ <%= image_tag(params[:action] == 'new' ? '' : @dynamic_new.cover_url, id: "avatar_image", :class=>"school_avatar dynamic_new_image" )%>
+ 上传封面
+ <%= file_field_tag 'cover',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
+
+
+
+
+ <%= f.select :category_id, options_for_select(Category.all.collect{|item| [item.name, item.id]}, @category_id), :class => "small" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <%= f.kindeditor :content,:width=>'87.5%',:editor_id=>'dynamic_new_editor' %>
+
+
+
+
+
+ <%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "dynamic_new_editor.sync();submit_message($(this));" %>
+
+<% end %>
+
+
diff --git a/app/views/dynamic_news/edit.html.erb b/app/views/dynamic_news/edit.html.erb
new file mode 100644
index 000000000..358e1b286
--- /dev/null
+++ b/app/views/dynamic_news/edit.html.erb
@@ -0,0 +1,23 @@
+
+
+<%= content_for(:header_tags) do %>
+ <%= import_ke(enable_at: false) %>
+<% end %>
+
+ <%=l(:label_new_dynamic_new)%>
+
+
+ <%= error_messages_for 'dynamic_new' %>
+ <%= render 'form' %>
+
diff --git a/app/views/dynamic_news/new.html.erb b/app/views/dynamic_news/new.html.erb
index ca5b83e66..2ea98560b 100644
--- a/app/views/dynamic_news/new.html.erb
+++ b/app/views/dynamic_news/new.html.erb
@@ -18,70 +18,5 @@
<%=l(:label_new_dynamic_new)%>
- <%= form_for(@dynamic_new, :url=> { :action => :create }, :html => {:id =>'system_messages-form',:multipart => true }) do |f| %>
-
-
- <%= image_tag('', id: "avatar_image", :class=>"school_avatar dynamic_new_image" )%>
- 上传图片
- <%= file_field_tag 'cover',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <%= f.kindeditor :content,:width=>'87.5%',:editor_id=>'system_message_editor' %>
-
-
-
-
-
- <%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "system_message_editor.sync();submit_message($(this));" %>
-
- <% end %>
+ <%= render 'form' %>
-
diff --git a/db/migrate/20191022031808_add_platform_to_dynamic_news.rb b/db/migrate/20191022031808_add_platform_to_dynamic_news.rb
new file mode 100644
index 000000000..11c5f8eda
--- /dev/null
+++ b/db/migrate/20191022031808_add_platform_to_dynamic_news.rb
@@ -0,0 +1,5 @@
+class AddPlatformToDynamicNews < ActiveRecord::Migration
+ def change
+ add_column :dynamic_news, :platform, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a7f3e0f25..5c878cb36 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20191021063319) do
+ActiveRecord::Schema.define(:version => 20191022031808) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -958,6 +958,7 @@ ActiveRecord::Schema.define(:version => 20191021063319) do
t.datetime "updated_at", :null => false
t.string "simple_intruduce"
t.integer "category_id", :null => false
+ t.string "platform"
end
add_index "dynamic_news", ["title"], :name => "index_dynamic_news_on_title"