应用上传附件功能

This commit is contained in:
nieguanghui 2014-04-09 09:25:24 +08:00
parent a9e9171441
commit bad170fdb2
6 changed files with 71 additions and 13 deletions

View File

@ -41,7 +41,7 @@ class SoftapplicationsController < ApplicationController
# POST /softapplications.json # POST /softapplications.json
def create def create
@softapplication = Softapplication.new(params[:softapplication]) @softapplication = Softapplication.new(params[:softapplication])
@softapplication.save_attachments(params[:attachments])
respond_to do |format| respond_to do |format|
if @softapplication.save if @softapplication.save
format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' } format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' }
@ -69,6 +69,12 @@ class SoftapplicationsController < ApplicationController
end end
end end
def add_attach
@softapplication = Softapplication.find(params[:id])
@softapplication.save_attachments(params[:attachments])
end
# DELETE /softapplications/1 # DELETE /softapplications/1
# DELETE /softapplications/1.json # DELETE /softapplications/1.json
def destroy def destroy

View File

@ -21,6 +21,7 @@ require "fileutils"
class Attachment < ActiveRecord::Base class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true belongs_to :container, :polymorphic => true
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :author, :class_name => "User", :foreign_key => "author_id"
validates_presence_of :filename, :author validates_presence_of :filename, :author

View File

@ -1,3 +1,4 @@
class Softapplication < ActiveRecord::Base class Softapplication < ActiveRecord::Base
attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id
acts_as_attachable
end end

View File

@ -1,12 +1,64 @@
<h3><%=l(:label_release_softapplication)%></h3> <h3><%= l(:label_release_softapplication)%></h3> <!-- <%= render 'form' %>
<!-- <%= render 'form' %>
<%= link_to 'Back', softapplications_path %> --> <%= link_to 'Back', softapplications_path %> -->
<%= labelled_form_for @softapplication, :url => {:controller => 'softapplications', :action => 'create'}, method: :post do |f| %>
<div class="box tabular"> <div id="put-bid-form" style="">
<%= render :partial => 'form', :locals => { :f => f } %> <%= form_for Softapplication.new, :url => {:controller => 'softapplications', :action => 'create'}, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %>
<%= submit_tag l(:button_create) %> <fieldset>
<legend>
<%= l(:label_attachment_plural) %>
</legend>
<tr style="width:700px; margin-left: -10px">
<td><%= l(:label_softapplication_name) %></td>
<td style="require, color: #bb0000"> * </td>: <td ><%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %></td>
<td><%= l(:label_softapplication_name_condition)%></td>
</tr></ br>
<br />
<br />
<tr style="width:800px;">
<td><%= l(:label_softapplication_version_available) %></td>
<td style="require, color: #bb0000"> * </td>: <td style="width: 100px"><%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %></td>
</tr></ br>
<br />
<br />
<tr style="width:800px;">
<td><%= l(:label_softapplication_type) %></td>
<td style="require, color: #bb0000"> * </td>: <td style="width: 100px"><%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %></td>
</tr></ br>
<br />
<br />
<tr style="width:800px;">
<td><%= l(:label_softapplication_description) %></td>
<td style="require, color: #bb0000"> * </td>: <td style="width: 100px"><%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %></td>
</tr></ br>
<br />
<br />
<%= render_flash_messages %>
<p id="put-bid-form-partial">
<%= render :partial => 'attachments/form' %>
</p>
</fieldset>
<%= submit_tag l(:button_create), :onclick => "return true" %>
<script type="text/javascript">
function j_submit () {
alert('start')
var submit_homework = function(){
$('#add_homework_form').clone().attr('action', '<%= url_for({:controller => "softapplications", :action => "create"})+".js" %>').ajaxSubmit()
};
alert('stop')
$.globalEval(submit_homework());
return false;
}
</script>
</div>
<% end %> <% end %>
</div> </div>

View File

@ -17,8 +17,6 @@
RedmineApp::Application.routes.draw do RedmineApp::Application.routes.draw do
resources :softapplications resources :softapplications
## new added by linchun #新竞赛相关 ## new added by linchun #新竞赛相关
resources :contests, only: [:index] do resources :contests, only: [:index] do
collection do collection do