From 87c70909beac2dc8cea45f3b296ef752b7a2fbca Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Mon, 28 Apr 2014 09:13:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=9C=A8=E5=BC=80=E6=BA=90?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=B7=BB=E5=8A=A0=E5=B8=96=E5=AD=90=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=B8=96=E5=AD=90?= =?UTF-8?q?=E7=9A=84URL,=E5=8D=B3=E5=B8=96=E5=AD=90=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/relative_memos_controller.rb | 25 ++++-- app/models/relative_memo.rb | 3 +- app/views/layouts/base_opensource_p.html.erb | 1 + .../_show_topics.html.erb | 2 +- app/views/open_source_projects/show.html.erb | 12 +-- ...0140428005537_add_url_to_relative_memos.rb | 5 ++ db/schema.rb | 77 ++++++++++++++++++- 7 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20140428005537_add_url_to_relative_memos.rb diff --git a/app/controllers/relative_memos_controller.rb b/app/controllers/relative_memos_controller.rb index 70d2f00c2..4c891e0a6 100644 --- a/app/controllers/relative_memos_controller.rb +++ b/app/controllers/relative_memos_controller.rb @@ -8,6 +8,8 @@ class RelativeMemosController < ApplicationController include NoUsesHelper before_filter :find_memo, :except => [:new, :create] + before_filter :find_osp, :only => [:create] + before_filter :require_login, :only => [:new, :create] layout 'base_opensource_p' @@ -88,15 +90,22 @@ class RelativeMemosController < ApplicationController # POST /open_source_projects # POST /open_source_projects.json def create - @open_source_project = OpenSourceProject.new(params[:open_source_project]) + @memo = RelativeMemo.new(params[:relative_memo]) + # @memo.url = "http://forge.trustie.net/open_source_projects" + @memo.osp_id = params[:open_source_project_id] + @memo.author_id = User.current.id + + @memo.save_attachments(params[:attachments] || (params[:relative_memo] && params[:relative_memo][:uploads])) respond_to do |format| - if @open_source_project.save - format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.'} - format.json { render json: @open_source_project, status: :created, location: @open_source_project } + if @memo.save + format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } + format.json { render json: @memo, status: :created, location: @memo } else - format.html { render action: "new" } - format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + flash[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" + # back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id) + format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + format.json { render json: @memo.errors, status: :unprocessable_entity } end end end @@ -145,4 +154,8 @@ class RelativeMemosController < ApplicationController render_404 nil end + + def back_memo_url + open_source_project_relative_memo_path(@open_source_project, (@memo.parent_id.nil? ? @memo : @memo.parent_id)) + end end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index a1532dcb2..eeef0eb9c 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -10,6 +10,7 @@ class RelativeMemo < ActiveRecord::Base has_many :no_uses, :as => :no_use, :dependent => :delete_all acts_as_taggable + acts_as_attachable validates_presence_of :osp_id, :subject #validates :content, presence: true @@ -106,7 +107,7 @@ class RelativeMemo < ActiveRecord::Base RelativeMemo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) parent.update_attribute(:updated_at, Time.now) end - forum.reset_counters! + # forum.reset_counters! end def sticky? diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index ce6b7cb22..c6127f832 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -13,6 +13,7 @@ <%= javascript_heads %> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> + <%= javascript_include_tag "ckeditor/ckeditor.js" %> <%= yield :header_tags -%> diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb index 3f51b06c7..47903d5c4 100644 --- a/app/views/open_source_projects/_show_topics.html.erb +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -42,7 +42,7 @@