[2] | 1 | <?xml version="1.0" encoding="iso-8859-1"?> |
---|
| 2 | <!DOCTYPE html |
---|
| 3 | PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 4 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
| 5 | |
---|
| 6 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
---|
| 7 | <head> |
---|
| 8 | <title>Module: FileColumnHelper</title> |
---|
| 9 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
---|
| 10 | <meta http-equiv="Content-Script-Type" content="text/javascript" /> |
---|
| 11 | <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" /> |
---|
| 12 | <script type="text/javascript"> |
---|
| 13 | // <![CDATA[ |
---|
| 14 | |
---|
| 15 | function popupCode( url ) { |
---|
| 16 | window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | function toggleCode( id ) { |
---|
| 20 | if ( document.getElementById ) |
---|
| 21 | elem = document.getElementById( id ); |
---|
| 22 | else if ( document.all ) |
---|
| 23 | elem = eval( "document.all." + id ); |
---|
| 24 | else |
---|
| 25 | return false; |
---|
| 26 | |
---|
| 27 | elemStyle = elem.style; |
---|
| 28 | |
---|
| 29 | if ( elemStyle.display != "block" ) { |
---|
| 30 | elemStyle.display = "block" |
---|
| 31 | } else { |
---|
| 32 | elemStyle.display = "none" |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | return true; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | // Make codeblocks hidden by default |
---|
| 39 | document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) |
---|
| 40 | |
---|
| 41 | // ]]> |
---|
| 42 | </script> |
---|
| 43 | |
---|
| 44 | </head> |
---|
| 45 | <body> |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | <div id="classHeader"> |
---|
| 50 | <table class="header-table"> |
---|
| 51 | <tr class="top-aligned-row"> |
---|
| 52 | <td><strong>Module</strong></td> |
---|
| 53 | <td class="class-name-in-header">FileColumnHelper</td> |
---|
| 54 | </tr> |
---|
| 55 | <tr class="top-aligned-row"> |
---|
| 56 | <td><strong>In:</strong></td> |
---|
| 57 | <td> |
---|
| 58 | <a href="../files/lib/file_column_helper_rb.html"> |
---|
| 59 | lib/file_column_helper.rb |
---|
| 60 | </a> |
---|
| 61 | <br /> |
---|
| 62 | </td> |
---|
| 63 | </tr> |
---|
| 64 | |
---|
| 65 | </table> |
---|
| 66 | </div> |
---|
| 67 | <!-- banner header --> |
---|
| 68 | |
---|
| 69 | <div id="bodyContent"> |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | <div id="contextContent"> |
---|
| 74 | |
---|
| 75 | <div id="description"> |
---|
| 76 | <p> |
---|
| 77 | This module contains helper methods for displaying and uploading files for |
---|
| 78 | attributes created by <tt>FileColumn</tt>’s <tt>file_column</tt> |
---|
| 79 | method. It will be automatically included into ActionView::Base, thereby |
---|
| 80 | making this module’s methods available in all your views. |
---|
| 81 | </p> |
---|
| 82 | |
---|
| 83 | </div> |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | </div> |
---|
| 87 | |
---|
| 88 | <div id="method-list"> |
---|
| 89 | <h3 class="section-bar">Methods</h3> |
---|
| 90 | |
---|
| 91 | <div class="name-list"> |
---|
| 92 | <a href="#M000001">file_column_field</a> |
---|
| 93 | <a href="#M000002">url_for_file_column</a> |
---|
| 94 | </div> |
---|
| 95 | </div> |
---|
| 96 | |
---|
| 97 | </div> |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | <!-- if includes --> |
---|
| 101 | |
---|
| 102 | <div id="section"> |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | <!-- if method_list --> |
---|
| 112 | <div id="methods"> |
---|
| 113 | <h3 class="section-bar">Public Instance methods</h3> |
---|
| 114 | |
---|
| 115 | <div id="method-M000001" class="method-detail"> |
---|
| 116 | <a name="M000001"></a> |
---|
| 117 | |
---|
| 118 | <div class="method-heading"> |
---|
| 119 | <a href="FileColumnHelper.src/M000001.html" target="Code" class="method-signature" |
---|
| 120 | onclick="popupCode('FileColumnHelper.src/M000001.html');return false;"> |
---|
| 121 | <span class="method-name">file_column_field</span><span class="method-args">(object, method, options={})</span> |
---|
| 122 | </a> |
---|
| 123 | </div> |
---|
| 124 | |
---|
| 125 | <div class="method-description"> |
---|
| 126 | <p> |
---|
| 127 | Use this helper to create an upload field for a file_column attribute. This |
---|
| 128 | will generate an additional hidden field to keep uploaded files during |
---|
| 129 | form-redisplays. For example, when called with |
---|
| 130 | </p> |
---|
| 131 | <pre> |
---|
| 132 | <%= file_column_field("entry", "image") %> |
---|
| 133 | </pre> |
---|
| 134 | <p> |
---|
| 135 | the following HTML will be generated (assuming the form is redisplayed and |
---|
| 136 | something has already been uploaded): |
---|
| 137 | </p> |
---|
| 138 | <pre> |
---|
| 139 | <input type="hidden" name="entry[image_temp]" value="..." /> |
---|
| 140 | <input type="file" name="entry[image]" /> |
---|
| 141 | </pre> |
---|
| 142 | <p> |
---|
| 143 | You can use the <tt>option</tt> argument to pass additional options to the |
---|
| 144 | file-field tag. |
---|
| 145 | </p> |
---|
| 146 | <p> |
---|
| 147 | Be sure to set the enclosing form’s encoding to |
---|
| 148 | ‘multipart/form-data’, by using something like this: |
---|
| 149 | </p> |
---|
| 150 | <pre> |
---|
| 151 | <%= form_tag {:action => "create", ...}, :multipart => true %> |
---|
| 152 | </pre> |
---|
| 153 | </div> |
---|
| 154 | </div> |
---|
| 155 | |
---|
| 156 | <div id="method-M000002" class="method-detail"> |
---|
| 157 | <a name="M000002"></a> |
---|
| 158 | |
---|
| 159 | <div class="method-heading"> |
---|
| 160 | <a href="FileColumnHelper.src/M000002.html" target="Code" class="method-signature" |
---|
| 161 | onclick="popupCode('FileColumnHelper.src/M000002.html');return false;"> |
---|
| 162 | <span class="method-name">url_for_file_column</span><span class="method-args">(object_name, method, suffix=nil)</span> |
---|
| 163 | </a> |
---|
| 164 | </div> |
---|
| 165 | |
---|
| 166 | <div class="method-description"> |
---|
| 167 | <p> |
---|
| 168 | Creates an URL where an uploaded file can be accessed. When called for an |
---|
| 169 | Entry object with id 42 (stored in <tt>@entry</tt>) like this |
---|
| 170 | </p> |
---|
| 171 | <pre> |
---|
| 172 | <%= url_for_file_column("entry", "image") |
---|
| 173 | </pre> |
---|
| 174 | <p> |
---|
| 175 | the following URL will be produced, assuming the file "test.png" |
---|
| 176 | has been stored in the "image"-column of an Entry object stored |
---|
| 177 | in <tt>@entry</tt>: |
---|
| 178 | </p> |
---|
| 179 | <pre> |
---|
| 180 | /entry/image/42/test.png |
---|
| 181 | </pre> |
---|
| 182 | <p> |
---|
| 183 | This will produce a valid URL even for temporary uploaded files, e.g. files |
---|
| 184 | where the object they are belonging to has not been saved in the database |
---|
| 185 | yet. |
---|
| 186 | </p> |
---|
| 187 | <p> |
---|
| 188 | If there is currently no uploaded file stored in the object’s column |
---|
| 189 | this method will return <tt>nil</tt>. |
---|
| 190 | </p> |
---|
| 191 | <p> |
---|
| 192 | If the optional <tt>suffix</tt> parameter is given, it will be inserted |
---|
| 193 | into the filename before the extension. So if the uploaded file is name |
---|
| 194 | "vancouver.jpg" and you have the following code in your view |
---|
| 195 | </p> |
---|
| 196 | <pre> |
---|
| 197 | <%= url_for_file_column("entry", "image", "thumb") %> |
---|
| 198 | </pre> |
---|
| 199 | <p> |
---|
| 200 | the resulting URL’s would point to a file |
---|
| 201 | "vancouver-thumb.jpg". This can be used to access different |
---|
| 202 | versions of a file as produced by <a |
---|
| 203 | href="FileColumn/Magick.html">FileColumn::Magick</a>, for example. |
---|
| 204 | </p> |
---|
| 205 | <p> |
---|
| 206 | Note that the object has to be stored in an instance variable. So if |
---|
| 207 | <tt>object_name</tt> is "entry" your object has to be stored in |
---|
| 208 | <tt>@entry</tt>. |
---|
| 209 | </p> |
---|
| 210 | </div> |
---|
| 211 | </div> |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | </div> |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | </div> |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | <div id="validator-badges"> |
---|
| 221 | <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> |
---|
| 222 | </div> |
---|
| 223 | |
---|
| 224 | </body> |
---|
| 225 | </html> |
---|