应用上传附件功能

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

View File

@ -21,6 +21,7 @@ require "fileutils"
class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
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"
validates_presence_of :filename, :author

View File

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

View File

@ -1,12 +1,64 @@
<h3><%=l(:label_release_softapplication)%></h3>
<!-- <%= render 'form' %>
<h3><%= l(:label_release_softapplication)%></h3> <!-- <%= render 'form' %>
<%= link_to 'Back', softapplications_path %> -->
<%= labelled_form_for @softapplication, :url => {:controller => 'softapplications', :action => 'create'}, method: :post do |f| %>
<div class="box tabular">
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<div id="put-bid-form" style="">
<%= 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| %>
<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 %>
</div>

View File

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