Views

Full pages rendered in the web browser are called views in Ruby on Rails. Views are usually displayed as a result of the end-user clicking on a link that is generated via the link_tofunction present in the menu generator. It is also possible to manually specify a URL to go directly to each full view. End-user web browser makes requests of the formhttps://rxg/portal/CONTROLLER_NAME/ACTION. TheCONTROLLER_NAME is typically the name of the custom portal and the ACTION is one of the various web pages of the portal that present the functionality.

In our main page layout example we had the following line of code:<%= link_to 'Home', { :action => :index }, { :class => 'menu' } %>. Lets now look closer at the action portion. The { :action => :index } portion says, I want to link to the full view called index. The corresponding file in your views folder is index.erb. The index view also happens to be the view displayed if no view is specified. This could also be thought of as the splash view.

Another way to look at it is that the action name, such asindex above, is determined from its filename. The portion before the .erb in the filename is the name of the action. For example, if the end-user web browser requests the URLhttps://rxg/portal/CONTROLLER_NAME/session_info, then the file session_info.erb will be used to render the presentation.

There are three valid suffixes on the filename that coincides with an action: .tablet.erb, .mobile.erb and simply.erb. This enables the administrator to create different presentations for different kinds of devices and/or browsers. By default, a desktop web browser that requests the URLhttps://rxg/portal/CONTROLLER_NAME/action, will loadaction.erb. Similarly, a web browser running on a mobile device (e.g., an iPhone, BlackBerry, etc.) will loadaction.mobile.erb. If the administrator does not wish to differentiate between the desktop, tablet, or mobile views, a singleaction.erb file may be created and that will always be used.

All of the views that ship with the default captive portal are functional as-is and require no modification. However if you would like to edit the verbiage or change the layout of a specific view, you can edit it as you see fit. The contents of a view file are HTML and embedded Ruby, similar to that of the layout file. Below is a simple example of a view.

<h2>Login</h2>

<%= portal_image_tag 'login.jpg' %>

<%= render :partial => 'login_form_account' %>

Notice that HTML elements (<h2>) are present side by side with embedded ruby elements (<% ruby code %>). Since the view will be rendered into the layout where the yield command is, the view file does not contain the HTML that forms the foundation of the page (e.g.,<head>, <body>, etc.).

Minimizing redundant HTML and embedded Ruby code is an important part of custom captive portal implementation. Ruby on Rails supports the use of page partials that are reusable within many views. To create a partial, put whatever HTML and/or embedded Ruby code into a file with a name that begins with an underscore (_) character. You may then reference the file name (without the underscore) in any view using the embedded Ruby code <%= render :partial => 'PARTIAL_FILE_NAME' %>to have the partial rendered in place.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.