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 @@ - 帖子来源:<%= link_to @open_source_project.url, @open_source_project.url%> + 帖子来源:<%= link_to topic.url, topic.url%> <%= no_use_link(topic, User.current) %> diff --git a/app/views/open_source_projects/show.html.erb b/app/views/open_source_projects/show.html.erb index 8b04183b1..0459e2399 100644 --- a/app/views/open_source_projects/show.html.erb +++ b/app/views/open_source_projects/show.html.erb @@ -2,7 +2,7 @@