Add named routes for attachments and use route helpers in #link_to_attachment.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11187 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f607a7a023
commit
4ebdcf13db
|
@ -91,14 +91,10 @@ module ApplicationHelper
|
||||||
# * :download - Force download (default: false)
|
# * :download - Force download (default: false)
|
||||||
def link_to_attachment(attachment, options={})
|
def link_to_attachment(attachment, options={})
|
||||||
text = options.delete(:text) || attachment.filename
|
text = options.delete(:text) || attachment.filename
|
||||||
action = options.delete(:download) ? 'download' : 'show'
|
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
|
||||||
opt_only_path = {}
|
html_options = options.slice!(:only_path)
|
||||||
opt_only_path[:only_path] = (options[:only_path] == false ? false : true)
|
url = send(route_method, attachment, attachment.filename, options)
|
||||||
options.delete(:only_path)
|
link_to text, url, html_options
|
||||||
link_to(h(text),
|
|
||||||
{:controller => 'attachments', :action => action,
|
|
||||||
:id => attachment, :filename => attachment.filename}.merge(opt_only_path),
|
|
||||||
options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates a link to a SCM revision
|
# Generates a link to a SCM revision
|
||||||
|
|
|
@ -257,10 +257,10 @@ RedmineApp::Application.routes.draw do
|
||||||
get 'projects/:id/repository', :to => 'repositories#show', :path => nil
|
get 'projects/:id/repository', :to => 'repositories#show', :path => nil
|
||||||
|
|
||||||
# additional routes for having the file name at the end of url
|
# additional routes for having the file name at the end of url
|
||||||
match 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/, :via => :get
|
get 'attachments/:id/:filename', :to => 'attachments#show', :id => /\d+/, :filename => /.*/, :as => 'named_attachment'
|
||||||
match 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/, :via => :get
|
get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment'
|
||||||
match 'attachments/download/:id', :controller => 'attachments', :action => 'download', :id => /\d+/, :via => :get
|
get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
|
||||||
match 'attachments/thumbnail/:id(/:size)', :controller => 'attachments', :action => 'thumbnail', :id => /\d+/, :via => :get, :size => /\d+/
|
get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/
|
||||||
resources :attachments, :only => [:show, :destroy]
|
resources :attachments, :only => [:show, :destroy]
|
||||||
|
|
||||||
resources :groups do
|
resources :groups do
|
||||||
|
|
|
@ -1063,6 +1063,20 @@ RAW
|
||||||
assert_equal ::I18n.t(:label_user_anonymous), t
|
assert_equal ::I18n.t(:label_user_anonymous), t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_link_to_attachment
|
||||||
|
a = Attachment.find(3)
|
||||||
|
assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>',
|
||||||
|
link_to_attachment(a)
|
||||||
|
assert_equal '<a href="/attachments/3/logo.gif">Text</a>',
|
||||||
|
link_to_attachment(a, :text => 'Text')
|
||||||
|
assert_equal '<a href="/attachments/3/logo.gif" class="foo">logo.gif</a>',
|
||||||
|
link_to_attachment(a, :class => 'foo')
|
||||||
|
assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
|
||||||
|
link_to_attachment(a, :download => true)
|
||||||
|
assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>',
|
||||||
|
link_to_attachment(a, :only_path => false)
|
||||||
|
end
|
||||||
|
|
||||||
def test_link_to_project
|
def test_link_to_project
|
||||||
project = Project.find(1)
|
project = Project.find(1)
|
||||||
assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
|
assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
|
||||||
|
|
Loading…
Reference in New Issue