vendor/plugins/rust-file_column/lib/file_column_helper.rb
# Creates an URL where an uploaded file can be accessed. When called for an Entry object with
# id 42 (stored in <tt>@entry</tt>) like this
#
#   <%= url_for_file_column(@entry, "image")
#
# the following URL will be produced, assuming the file "test.png" has been stored in
# the "image"-column of an Entry object stored in <tt>@entry</tt>:
#
#  /entry/image/42/test.png
#
# This will produce a valid URL even for temporary uploaded files, e.g. files where the object
# they are belonging to has not been saved in the database yet.
#
# The URL produces, although starting with a slash, will be relative
# to your app's root. If you pass it to one rails' +image_tag+
# helper, rails will properly convert it to an absolute
# URL. However, this will not be the case, if you create a link with
# the +link_to+ helper. In this case, you can pass <tt>:absolute =>
# true</tt> to +options+, which will make sure, the generated URL is
# absolute on your server.  Examples:
#
#    <%= image_tag url_for_file_column(@entry, "image") %>
#    <%= link_to "Download", url_for_file_column(@entry, "image", :absolute => true) %>
#
# If there is currently no uploaded file stored in the object's column this method will
# return +nil+.
Creates an URL where an uploaded file can be accessed. When called for an Entry object with
id 42 (stored in @entry) like this



the following URL will be produced, assuming the file "test.png" has been stored in
the "image"-column of an Entry object stored in @entry.



This will produce a valid URL even for temporary uploaded files, e.g. files where the object
they are belonging to has not been saved in the database yet.

The URL produces, although starting with a slash, will be relative
to your app's root. If you pass it to one rails' +image_tag+
helper, rails will properly convert it to an absolute
URL. However, this will not be the case, if you create a link with
the +link_to+ helper. In this case, you can pass :absolute =>
true to +options+, which will make sure, the generated URL is
absolute on your server.  Examples.



If there is currently no uploaded file stored in the object's column this method will
return +nil+.
Creates an URL where an uploaded file can be accessed . When called for an Entry object with id 42 ( stored in @entry ) like this the following URL will be produced assuming the file " test . png " has been stored in the " image " - column of an Entry object stored in @entry . This will produce a valid URL even for temporary uploaded files e . g . files where the object they are belonging to has not been saved in the database yet . The URL produces although starting with a slash will be relative to your app ' s root . If you pass it to one rails ' + image_tag + helper rails will properly convert it to an absolute URL . However this will not be the case if you create a link with the + link_to + helper . In this case you can pass : absolute = > true to + options + which will make sure the generated URL is absolute on your server . Examples . If there is currently no uploaded file stored in the object ' s column this method will return + nil + .
def url_for_file_column(object, method, options=nil)
    case object
    when String, Symbol
      object = instance_variable_get("@#{object.to_s}")
    end
    subdir = nil
    absolute = false
    if options
      case options
      when Hash
        subdir = options[:subdir]
        absolute = options[:absolute]
      when String, Symbol
        subdir = options
      end
    end
    relative_path = object.send("#{method}_relative_path", subdir)
    return nil unless relative_path
    url = ""
    url << request.relative_url_root.to_s if absolute
    url << "/"
    url << object.send("#{method}_options")[:base_url] << "/"
    url << relative_path
  end
def url_for_file_column ( object , method , options = nil ) case object when String , Symbol object = instance_variable_get ( "@#{object.to_s}" ) end subdir = nil absolute = false if options case options when Hash subdir = options [ :subdir ] absolute = options [ :absolute ] when String , Symbol subdir = options end end relative_path = object . send ( "#{method}_relative_path" , subdir ) return nil unless relative_path url = "" url << request . relative_url_root . to_s if absolute url << "/" url << object . send ( "#{method}_options" ) [ :base_url ] << "/" url << relative_path end
Creates an URL where an uploaded file can be accessed.
Creates an URL where an uploaded file can be accessed .
# parse options
object
<not_specific>
method
<not_specific>
options
<not_specific>