Application menu

Lets look at how application menu is rendered. Our example is defined in notes_renderer.rb.

 

########################################################################
# NotesRenderer defines methods for rendering Notes application.
########################################################################
class NotesRenderer < DcRenderer

########################################################################
# Default method will render application menu.
########################################################################
def default
  @parent.render(partial: 'notes/menu', formats: [:html])
end
end
 

Our NotesRenderer inherits from DcRenderer and implements default method which invokes Rails partial render and passes notes/menu parameter. Rails assumes that partial file will be located in views/notes/_menu.html.erb file. Lets look the contents of the file.

 

<ul class="app-menu">
  <li class="dc-link dc-animate">
    <%= dc_link_to 'Report', 'table', {controller: :cmsedit, table: :dc_dummy,
        formname: 'notes_report', action: 'new'}, target: 'iframe_edit' %>
  </li>
</ul>
<hr class='hr-green'>

<%= dc_iframe_edit('note') %>

 

We use linked list for application menu. Link button will have ''Report'' caption preceded with table icon. Link will load notes_report form into iframe_edit iframe. Since our form is not related to Mongo collection we must specify :dc_dummy as table parameter. We also specify new action otherwise cmsedit controller will throw an error. We can put as many links as we want. When they are wrapped in dc-link and dc-animate class they will appear as buttons in the browser.

 

Below the menu is drawn horizontal line to separate menu from form.

 

At the bottom we put iframe code. Iframe code will be provided by dc_iframe_edit helper method which can, beside model name, accept additional hash parameters similar to creating link to a form. These parameters will instruct iframe which form to load when first displayed. In our example, notes form will be loaded for notes collection. Form will display list of notes for current logged user.

 

Do you have a felling that we are out of order here? In our next chapter we will introduce Note document model.


Last update: 08.05.2018