Module | Camping::Base |
In: |
lib/camping-unabridged.rb
|
Camping::Base is built into each controller by way of the generic routing class Camping::R. In some ways, this class is trying to do too much, but it saves code for all the glue to stay in one place. Forgivable, considering that it‘s only really a handful of methods and accessors.
Everything in this module is accessable inside your controllers.
T | = | {} |
L | = | :layout |
body | [RW] | |
cookies | [RW] | |
env | [RW] | |
headers | [RW] | |
input | [RW] | |
request | [RW] | |
root | [RW] | |
state | [RW] | |
status | [RW] |
The default prefix for Camping model classes is the topmost module name lowercase and followed with an underscore.
Tepee::Models::Page.table_name_prefix #=> "tepee_pages"
Finds a template, returning either:
false # => Could not find template true # => Found template in Views instance of Tilt # => Found template in a file
You can directly return HTML form your controller for quick debugging by calling this method and pass some Markaby to it.
module Nuts::Controllers class Info def get; mab{ code @headers.inspect } end end end
You can also pass true to use the :layout HTML wrapping method
Called when a controller was not found. You can override this if you want to customize the error page:
module Nuts def r404(path) @path = path render :not_found end end
Called when an exception is raised. However, if there is a parse error in Camping or in your application‘s source code, it will not be caught.
k is the controller class, m is the request method (GET, POST, etc.) and e is the Exception which can be mined for useful info.
Be default this simply re-raises the error so a Rack middleware can handle it, but you are free to override it here:
module Nuts def r500(klass, method, exception) send_email_alert(klass, method, exception) render :server_error end end
Called if an undefined method is called on a controller, along with the request method m (GET, POST, etc.)
Formulate a redirect response: a 302 status with Location header and a blank body. Uses Helpers#URL to build the location from a controller route or path.
So, given a root of localhost:3301/articles:
redirect "view/12" # redirects to "//localhost:3301/articles/view/12" redirect View, 12 # redirects to "//localhost:3301/articles/view/12"
NOTE: This method doesn‘t magically exit your methods and redirect. You‘ll need to return redirect(…) if this isn‘t the last statement in your code, or throw :halt if it‘s in a helper.
See: Controllers
Display a view, calling it by its method name v. If a layout method is found in Camping::Views, it will be used to wrap the HTML.
module Nuts::Controllers class Show def get @posts = Post.find :all render :index end end end
All requests pass through this method before going to the controller. Some magic in Camping can be performed by overriding this method.