Example Customization

One very simple and common portal customization is to change the display of the usage plans. A quick search of the captive portal directory structure reveals the following:

$ ls | grep usage
_current_usage_plan.erb
_online_usage.erb
_usage_plan.erb
_usage_plan_purchase_link.erb
usage_plan_charge.erb
usage_plan_list.erb
usage_plan_purchase.erb

The display of an individual usage plan are rendered by the partial _usage_plan.erb and the display of the set of all available usage plans is rendered by the viewusage_plan_list.erb.

The contents of the default usage_plan_list.erbshould resemble the following:

<h2>Usage Plan List</h2>

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

<table>

  <% @usage_plans.each do |usage_plan| %>

    <tr>
      <td>
        <%= render :partial => 'usage_plan',
                      :object => usage_plan %>
      </td>
      <td>
        <%= render :partial => 'usage_plan_purchase_link',
                      :locals => { :usage_plan => usage_plan } %>
      </td>
    </tr>

    <tr><td> <br/> </td></tr>

  <% end %>

</table>

One simple way to change the order of the list of usage plans is to modify the looping structure. The default structure

@usage_plans.each do |usage_plan|

generates a list that may appear to be randomly ordered. To generate a list of the usage plans sorted by price, the looping structure should be changed to:

@usage_plans.sort_by(&:price_cents).each do |usage_plan|

To generate a list of the usage plans sorted by name, the looping structure should be changed to:

@usage_plans.sort_by(&:name).each do |usage_plan|

A custom sort order may be easily achieved by using the note field present in each usage plan record. Place a number (prefixed with a zero for multiple digits) inside the note field. Then change the looping structure to:

@usage_plans.sort_by(&:note).each do |usage_plan|

Another common portal customization is to change the layout of the usage plan list. For example, instead of a simple list, the operator may desire to have a multicolumn column list. One simple way to achieve this is add a variable to keep track of which column the usage plan should appear in. For example:

<h2>Usage Plan List</h2>

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

<table>

  <% @u_p_cnt = 0 %>
  <% @u_p_columns = 3 %>

  <% @usage_plans.each do |usage_plan| %>

    <% if @u_p_cnt % @u_p_columns == 0 %>
      <tr><td>
    <% else %>
      <td>
    <% end %>

        <%= render :partial => 'usage_plan',
                      :object => usage_plan %>
        <br/>
        <%= render :partial => 'usage_plan_purchase_link',
                      :locals => { :usage_plan => usage_plan } %>

    <% if @u_p_cnt % @u_p_columns == 0 %>
      </td></tr>
    <% else %>
      </td>
    <% end %>

    <% @u_p_cnt = @u_p_cnt + 1 %>

  <% end %>

</table>

The code above will generate a three column list of usage plans. The @up_cnt variable starts at zero and is incremented every time a usage plan is rendered. Every third usage plan (as determined by the modulo operation), a new table row is created. To change the number of rows, one would only need to change the value of the @u_p_columnsvariable.


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