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

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

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