File Upload Fixes

Dunno why this was buggered again. ":back" doesn't seem to function as it used to.
Also, when uploading a file from page "foo", it's important to return to "foo" after
a successful upload, rather than redirecting to the HomePage.

Finally, a favicon tweak.
master
Jacques Distler 2009-02-18 01:40:11 -06:00
parent d7c445178b
commit 7f2b16e78d
5 changed files with 9 additions and 11 deletions

View File

@ -18,7 +18,7 @@ class FileController < ApplicationController
new_file = @web.wiki_files.create(params['file'])
if new_file.valid?
flash[:info] = "File '#{@file_name}' successfully uploaded"
redirect_to_page(@page_name)
redirect_to(params['referring_page'])
else
# pass the file with errors back into the form
@file = new_file

View File

@ -1,6 +1,7 @@
<%-
@title = "Upload #{h @file_name}"
@hide_navigation = false
@referring_page ||= request.env["HTTP_REFERER"]
-%>
<%= error_messages_for 'file' %>
@ -8,6 +9,7 @@
<% form_tag({ :controller => 'file', :web => @web_name, :action => 'file' },
{ 'multipart' => true , 'accept-charset' => 'utf-8' }) do %>
<div class="inputFieldWithPrompt">
<input type="hidden" name="referring_page" value="<%= h @referring_page %>" />
<%= hidden_field 'file', 'file_name' %>
<label for="file_content"><b>Content of <%= h @file_name %> to upload</b>:</label>
<br />
@ -15,7 +17,7 @@
<br />
Please note that the file you are uploading will be named <%= h @file_name %> on the wiki -
regardless of how it is named on your computer. To change the wiki name of the file, please go
<%= link_to :back %> and edit the wiki page that refers to the file.
<%= link_to("back", @referring_page) %> and edit the wiki page that refers to the file.
</div>
<div class="inputFieldWithPrompt">
<label for="file_description"><b>Description</b>:</label>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -89,10 +89,10 @@ class FileControllerTest < ActionController::TestCase
end
def test_pic_upload_end_to_end
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
# edit and re-render a page so that it has an "unknown file" link to 'rails-e2e.gif'
PageRenderer.setup_url_generator(StubUrlGenerator.new)
renderer = PageRenderer.new
@wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]',
@wiki.revise_page('wiki1', 'Oak', '[[rails-e2e.gif:pic]]',
Time.now, 'AnonymousBrave', renderer)
assert_equal "<p><span class='newWikiWord'>rails-e2e.gif<a href='../file/rails-e2e.gif'>" +
"?</a></span></p>",
@ -112,14 +112,15 @@ class FileControllerTest < ActionController::TestCase
# updated from post to get - post fails the spam protection (no javascript)
# Moron! If substituting GET for POST actually works, you
# have much, much bigger problems.
r = get :file, :web => 'wiki1',
r = get :file, :web => 'wiki1', :referring_page => '/wiki1/show/Oak',
:file => {:file_name => 'rails-e2e.gif',
:content => StringIO.new(picture),
:description => 'Rails, end-to-end'}
assert_redirected_to '/wiki1/show/Oak'
assert @web.has_file?('rails-e2e.gif')
assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content)
PageRenderer.setup_url_generator(StubUrlGenerator.new)
@wiki.revise_page('wiki1', 'HomePage', 'Try [[rails-e2e.gif:pic]] again.',
@wiki.revise_page('wiki1', 'Oak', 'Try [[rails-e2e.gif:pic]] again.',
Time.now, 'AnonymousBrave', renderer)
assert_equal "<p>Try <img alt='Rails, end-to-end' src='../file/rails-e2e.gif'/> again.</p>",
renderer.display_content

View File

@ -144,7 +144,6 @@ module ActionController # :nodoc:
set_content_length!
convert_content_type!
convert_language!
convert_expires!
convert_cookies!
end
@ -244,10 +243,6 @@ module ActionController # :nodoc:
headers["Content-Language"] = headers.delete("language") if headers["language"]
end
def convert_expires!
headers["Expires"] = headers.delete("") if headers["expires"]
end
def convert_cookies!
headers['Set-Cookie'] = Array(headers['Set-Cookie']).compact
end