From 64895a75ed2013ef7812e58412a1f8b812126102 Mon Sep 17 00:00:00 2001 From: wanglinchun Date: Fri, 11 Apr 2014 17:16:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8A=E4=BC=A0=E6=88=AA?= =?UTF-8?q?=E5=9B=BE+=E5=BA=94=E7=94=A8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 2 +- app/controllers/contests_controller.rb | 11 +++++------ app/controllers/softapplications_controller.rb | 4 ++++ app/helpers/application_helper.rb | 8 ++++++++ app/models/contesting_project.rb | 6 +----- .../contests/show_softapplication.html.erb | 2 +- app/views/softapplications/show.html.erb | 17 ++++++++++++++++- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 01d2ea89..0c42c405 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -172,7 +172,7 @@ private @attachment = Attachment.find(params[:id]) # Show 404 if the filename in the url is wrong raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename - unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' + unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' @project = @attachment.project end rescue ActiveRecord::RecordNotFound diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 4ca1c193..ccc5c51a 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -294,7 +294,7 @@ class ContestsController < ApplicationController softapplication = Softapplication.find(params[:contest]) contest_message = params[:contest_for_save][:contest_message] if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 - if ContestingSoftapplication.create_contesting(@contest.id, softapplication.id, contest_message) + if ContestingSoftapplication.create_softapplication_contesting(@contest.id, softapplication.id, contest_message) flash.now[:notice] = l(:label_bidding_contest_succeed) end else @@ -303,12 +303,11 @@ class ContestsController < ApplicationController @contesting_softapplication = @contest.contesting_softapplications - render :text => params.to_json - # respond_to do |format| + respond_to do |format| - # format.html { redirect_to :back } - # format.js - # end + format.html { redirect_to :back } + format.js + end end ## 新建留言 def create diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 0a0f2541..a1410722 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -15,6 +15,10 @@ class SoftapplicationsController < ApplicationController def show @softapplication = Softapplication.find(params[:id]) @jours = @softapplication.journals_for_messages.order('created_on DESC') + @image_results = [] + @softapplication.attachments.each do |f| + f.image? ? @image_results << f : @image_results + end @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 344238e8..8533c401 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -111,6 +111,14 @@ module ApplicationHelper link_to text, url, html_options end + def link_to_attachment_img(attachment, options={}) + text = options.delete(:text) || attachment.filename + route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path + html_options = options.slice!(:only_path) + url = send(route_method, attachment, attachment.filename, options) + image_tag url, html_options + end + # Generates a link to a SCM revision # Options: # * :text - Link text (default to the formatted revision) diff --git a/app/models/contesting_project.rb b/app/models/contesting_project.rb index c0c36054..cb2a7fe3 100644 --- a/app/models/contesting_project.rb +++ b/app/models/contesting_project.rb @@ -18,11 +18,7 @@ class ContestingProject < ActiveRecord::Base self.create(:user_id => User.current.id, :contest_id => contest_id, :project_id => project_id, :description => description) end - - def self.cerate_softapplication_contesting(contest_id, softapplication_id, description = nil) - self.create_softapplication(:user_id => User.current.id, :contest_id => contest_id, - :softapplication_id => softapplication_id, :description => description) - end + def update_reward(which) self.update_attribute(:reward,which) diff --git a/app/views/contests/show_softapplication.html.erb b/app/views/contests/show_softapplication.html.erb index fd643a0b..3d6a1d73 100644 --- a/app/views/contests/show_softapplication.html.erb +++ b/app/views/contests/show_softapplication.html.erb @@ -96,7 +96,7 @@ -
+
<%= render :partial => 'softapplication_list', :locals => {:contesting_softapplication => @contesting_softapplication,:contest => @contest} %>
diff --git a/app/views/softapplications/show.html.erb b/app/views/softapplications/show.html.erb index e3e64900..03e49925 100644 --- a/app/views/softapplications/show.html.erb +++ b/app/views/softapplications/show.html.erb @@ -1,3 +1,12 @@ + + +

<%= notice %>

@@ -32,8 +41,14 @@
软件截图:
-
+
+ <% @image_results.take(4).each do |attachment| %> + <%= link_to_attachment_img attachment, :class => "soft-application", :download => "true" %> + <% end %> +
+
+