Aura
→
Helpers
Helpers
Helpers are defined and used exactly as how you would in Sinatra.
Defining helpers
Create a file in the app/helpers/
folder of your app.
[app/helpers/my_helpers.rb (rb)]
class Main
module MyHelpers
def who_is_awesome
"You are!"
end
end
helpers MyHelpers
end
Using helpers in views
You can then use it in views.
[app/views/index.haml (haml)]
%div.question
Who is awesome?
%div.answer
= who_is_awesome
Using helpers in routes
Yeah, you can.
[app/routes/foo.rb (rb)]
class Main
get '/who_is_awesome' do
@who = who_is_awesome
show :index
end
end
Admin helpers
- admin_back_to_dashboard Renders a 'back to dashboard' link in the sidebar.
- admin_icon Draws an img tag of the given icon.
- admin_watermark Shows the link to the admin page from the public site.
- show_admin Renders an admin page with the admin template.
Page helpers
- body_class Sets or gets the class for the body.
- link_to Builds a link.
- title Sets or gets the title for the page.
Helpers
- checkbox Draws a checkbox with a hidden field.
- h Escapes an HTML string.
- html Sanitizes HTML with Markdown and Textile support.
- labeled_checkbox Draws a checkbox with a label.
- layout Defines a layout to use.
- show Shows a given template.
Template helpers
- content_for! Like content_for, but overwrites any blocks.
- content_for? Synonym of has_content?
- has_content? Checks if a given content block is defined.
- partial Renders a partial.
- yield_content_of Loads a given template and yields a certain content block of it.
User helpers
- current_user Returns the current user as an instance of {Aura::Models::User}.
- logged_in? Checks if there is a user logged in or not.
- require_login Ensures that a route is only accessible to logged in users.
Flash helpers
- flash_error Flashes an error.
- flash_errors Returns a list of errors to flash.
- flash_errors? Checks if there are errors to flash.
- flash_message Flashes a message.
- flash_messages Returns a list of messages to flash.
- flash_messages? Checks if there are messages to flash.