首页 > 代码库 > Rails redmine upload
Rails redmine upload
controller
def uploadss
@attachment = Attachment.new(:file => request.raw_post)
@attachment.author = User.current
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
@attachment.files_to_final_location
puts @attachment.diskfile
respond_to do |format|
format.js
format.api {
if saved
render :action => ‘upload‘, :status => :created
else
render_validation_errors(@attachment)
end
}
end
end
routes
match ‘uploadss‘, :to => ‘foos#uploadss‘, :via => :post
erb
<span class="add_attachment">
<%= file_field_tag ‘attachments[dummy][file]‘,
:id => nil,
:class => ‘file_selector‘,
:multiple => true,
:size => 100,
:onchange => ‘uploadBlob(this.files[0],"uploadss.js",1,"");‘,
:data =http://www.mamicode.com/> {
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
:max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
:max_concurrent_uploads => Redmine::Configuration[‘max_concurrent_ajax_uploads‘].to_i,
:upload_path => "uploadss.js",
:description_placeholder => l(:label_optional_description)
} %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</span>
<% content_for :header_tags do %>
<%= javascript_include_tag ‘attachments‘ %>
<%= javascript_include_tag ‘test‘, :plugin=>‘redmine_standard‘ %>
<% end %>