可以在开源社区添加帖子,并且添加了帖子的URL,即帖子来源

This commit is contained in:
fanqiang 2014-04-28 09:13:57 +08:00
parent 07b75924d8
commit 87c70909be
7 changed files with 108 additions and 17 deletions

View File

@ -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

View File

@ -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?

View File

@ -13,6 +13,7 @@
<%= javascript_heads %>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<%= javascript_include_tag "ckeditor/ckeditor.js" %>
<!-- page specific tags -->
<%= yield :header_tags -%>
</head>

View File

@ -42,7 +42,7 @@
</span></td>
</tr>
<tr>
<td align="left" colspan="2" ><span class="font_lighter">帖子来源:<%= link_to @open_source_project.url, @open_source_project.url%> </span></td>
<td align="left" colspan="2" ><span class="font_lighter">帖子来源:<%= link_to topic.url, topic.url%> </span></td>
<td align="left"><%= no_use_link(topic, User.current) %> </td>
</tr>
<tr>

View File

@ -2,7 +2,7 @@
<div id="add-memo" class='lz' style="display: none; padding: 20px;">
<h3><%=l(:label_memo_new)%></h3>
<% if User.current.logged? %>
<%#= labelled_form_for(@memo, :url => forum_memos_path(1), :html => {:multipart => true} ) do |f| %>
<%= labelled_form_for(@memo, :url => open_source_project_relative_memos_path(@open_source_project), :html => {:multipart => true} ) do |f| %>
<% if @memo.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@memo.errors.count, "error") %> prohibited this memo from being saved:</h2>
@ -13,17 +13,17 @@
<% end %>
</ul>
</div>
<% #end %>
<% end %>
<div class="actions" style="max-width:680px">
<p><%= f.text_field :subject, :required => true%></p>
<p style="max-width:680px"><%= f.text_area :content, :required => true, :id => 'editor02' %></p>
<script type="text/javascript">var ckeditor=CKEDITOR.replace('editor02');</script>
<br/>
<p>
<%= l(:label_attachment_plural) %><br />
<%= render :partial => 'attachments/form', :locals => {:container => @memo} %>
<%#= l(:label_attachment_plural) %><br />
<%#= render :partial => 'attachments/form', :locals => {:container => @memo} %>
</p>
<%#= f.submit :value => l(:label_memo_create) %>
<%= f.submit :value => l(:label_memo_create) %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-memo").hide(); return false;' %>
</div>
<% end %>
@ -32,7 +32,7 @@
<!--modified by huang-->
<% #= link_to '发布帖子', new_forum_memo_path(@forum), :class => 'icon icon-add' %>
<span>
<%#= link_to l(:label_memo_new_from_forum), new_forum_memo_path(@forum), :class => 'icon icon-add',
<%= link_to l(:label_memo_new_from_forum), new_open_source_project_relative_memo_path(@open_source_project), :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-memo", "memo_subject"); return false;' if User.current.logged? %>
</span>

View File

@ -0,0 +1,5 @@
class AddUrlToRelativeMemos < ActiveRecord::Migration
def change
add_column :relative_memos, :url, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140411011700) do
ActiveRecord::Schema.define(:version => 20140428005537) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -185,6 +185,38 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
add_index "comments", ["author_id"], :name => "index_comments_on_author_id"
add_index "comments", ["commented_id", "commented_type"], :name => "index_comments_on_commented_id_and_commented_type"
create_table "contesting_projects", :force => true do |t|
t.integer "project_id"
t.string "contest_id"
t.integer "user_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "reward"
end
create_table "contesting_softapplications", :force => true do |t|
t.integer "softapplication_id"
t.integer "contest_id"
t.integer "user_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "reward"
end
create_table "contests", :force => true do |t|
t.string "name"
t.string "budget", :default => ""
t.integer "author_id"
t.date "deadline"
t.string "description"
t.integer "commit"
t.string "password"
t.datetime "created_on", :null => false
t.datetime "updated_on", :null => false
end
create_table "courses", :force => true do |t|
t.integer "tea_id"
t.string "name"
@ -521,6 +553,13 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
add_index "issues", ["status_id"], :name => "index_issues_on_status_id"
add_index "issues", ["tracker_id"], :name => "index_issues_on_tracker_id"
create_table "join_in_competitions", :force => true do |t|
t.integer "user_id"
t.integer "competition_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "join_in_contests", :force => true do |t|
t.integer "user_id"
t.integer "bid_id"
@ -784,6 +823,7 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
t.datetime "updated_at", :null => false
t.integer "viewed_count_crawl", :default => 0
t.integer "viewed_count_local", :default => 0
t.string "url"
end
create_table "repositories", :force => true do |t|
@ -814,6 +854,8 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
create_table "schools", :force => true do |t|
t.string "name"
t.string "province"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "seems_rateable_cached_ratings", :force => true do |t|
@ -856,6 +898,21 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
t.string "description"
end
create_table "softapplications", :force => true do |t|
t.string "name"
t.string "description"
t.integer "app_type_id"
t.string "app_type_name"
t.string "android_min_version_available"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "contest_id"
t.integer "softapplication_id"
t.integer "is_public"
t.string "application_developers"
end
create_table "students_for_courses", :force => true do |t|
t.integer "student_id"
t.integer "course_id"
@ -962,6 +1019,7 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
t.string "teacher_realname"
t.string "student_realname"
t.string "location_city"
t.integer "school_id"
end
create_table "user_grades", :force => true do |t|
@ -985,6 +1043,19 @@ ActiveRecord::Schema.define(:version => 20140411011700) do
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
create_table "user_scores", :force => true do |t|
t.integer "user_id", :null => false
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "level"
t.integer "file"
t.integer "issue"
end
create_table "user_statuses", :force => true do |t|
t.integer "changesets_count"
t.integer "watchers_count"