Module | Merb::ControllerMixin |
In: |
lib/merb-core/controller/mixins/controller.rb
|
Module that is mixed in to all implemented controllers.
Marks a cookie as deleted and gives it an expires stamp in the past. This method is used primarily internally in Merb.
Use the cookies hash to manipulate cookies instead.
name<~to_s>: | A name for the cookie to delete. |
:api: public
Escapes the string representation of obj and escapes it for use in XML.
obj<~to_s>: | The object to escape for use in XML. |
String: | The escaped object. |
:api: public
Uses the nginx specific +X-Accel-Redirect+ header to send a file directly from nginx.
Unless Content-Disposition is set before calling this method, it is set to attachment with streamed file name.
For more information, see the nginx wiki: wiki.codemongers.com/NginxXSendfile
and the following sample gist: gist.github.com/11225
there‘s also example application up on GitHub:
github.com/michaelklishin/nginx-x-accel-redirect-example-application/tree/master
path<String>: | Path to file to send to the client. |
content_type<String>: | content type header value. By default is set to empty string to let Nginx detect it. |
String: | precisely a single space. |
:api: public
url<String>: | URL to redirect to. It can be either a relative or fully-qualified URL. |
opts<Hash>: | An options hash (see below) |
:message<Hash>: | Messages to pass in url query string as value for "_message" |
:permanent<Boolean>: | When true, return status 301 Moved Permanently |
String: | Explanation of redirect. |
redirect("/posts/34") redirect("/posts/34", :message => { :notice => 'Post updated successfully!' }) redirect("http://www.merbivore.com/") redirect("http://www.merbivore.com/", :permanent => true)
:api: public
Renders the block given as a parameter using chunked encoding.
&blk: | A block that, when called, will use send_chunks to send chunks of data down to the server. The chunking will terminate once the block returns. |
def stream prefix = '<p>' suffix = "</p>\r\n" render_chunked do IO.popen("cat /tmp/test.log") do |io| done = false until done sleep 0.3 line = io.gets.chomp if line == 'EOF' done = true else send_chunk(prefix + line + suffix) end end end end end
:api: public
&blk: | A proc that should get called outside the mutex, and which will return the value to render. |
Proc: | A block that the server can call later, allowing Merb to release the thread lock and render another request. |
:api: public
Renders the passed in string, then calls the block outside the mutex and after the string has been returned to the client.
str<String>: | A String to return to the client. |
&blk: | A block that should get called once the string has been returned. |
Proc: | A block that Mongrel can call after returning the string to the user. |
:api: public
Enqueu a block to run in a background thread outside of the request response dispatch
&blk: | proc to run later |
run_later do
SomeBackgroundTask.run
end
:api: public
Writes a chunk from render_chunked to the response that is sent back to the client. This should only be called within a render_chunked block.
data<String>: | a chunk of data to return. |
:api: public
Send binary data over HTTP to the user as a file download. May set content type, apparent file name, and specify whether to show data inline or download as an attachment.
data<String>: | Path to file to send to the client. |
opts<Hash>: | Options for sending the data (see below). |
:disposition<String>: | The disposition of the file send. Defaults to "attachment". |
:filename<String>: | The name to use for the file. Defaults to the filename of file. |
:type<String>: | The content type. |
:api: public
Sends a file over HTTP. When given a path to a file, it will set the right headers so that the static file is served directly.
file<String>: | Path to file to send to the client. |
opts<Hash>: | Options for sending the file (see below). |
:disposition<String>: | The disposition of the file send. Defaults to "attachment". |
:filename<String>: | The name to use for the file. Defaults to the filename of file. |
:type<String>: | The content type. |
IO: | An I/O stream for the file. |
:api: public
Sets a cookie to be included in the response.
If you need to set a cookie, then use the cookies hash.
name<~to_s>: | A name for the cookie. |
value<~to_s>: | A value for the cookie. |
expires<~gmtime:~strftime, Hash>: | An expiration time for the cookie, or a hash of cookie options. |
:api: public
Streams a file over HTTP.
opts<Hash>: | Options for the file streaming (see below). |
&stream: | A block that, when called, will return an object that responds to get_lines for streaming. |
:disposition<String>: | The disposition of the file send. Defaults to "attachment". |
:type<String>: | The content type. |
:content_length<Numeric>: | The length of the content to send. |
:filename<String>: | The name to use for the streamed file. |
stream_file({ :filename => file_name, :type => content_type, :content_length => content_length }) do |response| AWS::S3::S3Object.stream(user.folder_name + "-" + user_file.unique_id, bucket_name) do |chunk| response.write chunk end end
:api: public