Site Tools


Hotfix release available: 2025-05-14b "Librarian". upgrade now! [56.2] (what's this?)
Hotfix release available: 2025-05-14a "Librarian". upgrade now! [56.1] (what's this?)
New release available: 2025-05-14 "Librarian". upgrade now! [56] (what's this?)
Hotfix release available: 2024-02-06b "Kaos". upgrade now! [55.2] (what's this?)
Hotfix release available: 2024-02-06a "Kaos". upgrade now! [55.1] (what's this?)
New release available: 2024-02-06 "Kaos". upgrade now! [55] (what's this?)
Hotfix release available: 2023-04-04b "Jack Jackrum". upgrade now! [54.2] (what's this?)
Hotfix release available: 2023-04-04a "Jack Jackrum". upgrade now! [54.1] (what's this?)
New release available: 2023-04-04 "Jack Jackrum". upgrade now! [54] (what's this?)
Hotfix release available: 2022-07-31b "Igor". upgrade now! [53.1] (what's this?)
Hotfix release available: 2022-07-31a "Igor". upgrade now! [53] (what's this?)
New release available: 2022-07-31 "Igor". upgrade now! [52.2] (what's this?)
New release candidate 2 available: rc2022-06-26 "Igor". upgrade now! [52.1] (what's this?)
New release candidate available: 2022-06-26 "Igor". upgrade now! [52] (what's this?)
Hotfix release available: 2020-07-29a "Hogfather". upgrade now! [51.4] (what's this?)
New release available: 2020-07-29 "Hogfather". upgrade now! [51.3] (what's this?)
New release candidate 3 available: 2020-06-09 "Hogfather". upgrade now! [51.2] (what's this?)
New release candidate 2 available: 2020-06-01 "Hogfather". upgrade now! [51.1] (what's this?)
New release candidate available: 2020-06-01 "Hogfather". upgrade now! [51] (what's this?)
Hotfix release available: 2018-04-22c "Greebo". upgrade now! [50.3] (what's this?)
Hotfix release available: 2018-04-22b "Greebo". upgrade now! [50.2] (what's this?)
view_helpers

Usage example

see_all_link(:total_count => <total records available>, :visible_count => <number of records initially displayed>, :update => <ID of div to update>, :url => <url of action that will render all the records>, :item_style => <style of each item that is rendered as list>)

Options: :total_count - This has to be the total records that are available for the given entity.

:visible_count - The number of records that will be initially displayed as well as when clicked on “See Less”

:url - This will be the action that is responsible for rendering all the records.

:update - This is the ID of the html element that will be updated with the response of the action that is specified in :url option.

:item_style - The “See All” link in most of the cases will be used to display list of records. When render a record in the view, each of the record should be wrapped within an html element with same css class. The name of the css class should be passed to this option.

E.g If I am rendering list of recommendations then, I need to wrap each recommendation within a common css class.

- recommendations_given.each do |recommendation|
  .a_dummy_style_name
    = "#{recommendation.title} - #{recommendation.user.full_name}"

The implementation of the “See All” link can be found in my_learnings/recommendations_given_controller and related views can be found at corresponding views folder.

Usage examples:

Type 1 (will generate an ajax pagination link)

= will_paginate(collection, :renderer => ManualPageInputPaginationLinkRenderer, :remote => {:hash_for_path => hash_for_xxx_path, :update => 'div_to_update'})

Type 2 (will generate an ajax pagination link which will point to the action from which the view was rendered)

= will_paginate(collection, :renderer => ManualPageInputPaginationLinkRenderer, :remote => :update => 'div_to_update'})

Type 3 (will generate a normal link)

= will_paginate(collection, :renderer => ManualPageInputPaginationLinkRenderer)

Options:

- :remote - Use this if the pagination has to be ajaxified.

- :remote ⇒ :hash_for_path - This options has to be a hash which points to an action. e.g. {:action ⇒ 'show', :controller ⇒ 'users'}. If one want to use a restful route then the hash_for* can be used here. e.g. hash_for_users_path. The hash_for* is created by rails for each of the routes defined in routes.rb.

- :remote ⇒ :update - Specify the ID of the html element that has to updated with the response.

The implementation of this pagination can be found in “views/my_learnings/recommendations/_index.html.haml”

Profile Page panel

This panel can be used to create panels similar to the ones seen on Profile View mockup. Usage of this helper avoids the code duplication for the header part of it and the panels on the page would be consistent.

 profile_page_panel(opts, &block)

Options:

options is a hash with the following keys

  • :title ⇒ The title of the panel,
  • :group_name ⇒ the group_name parameter passed to panel_for
  • :side_panel ⇒ if true then panel is aligned on the right most of the page otherwise on the left side
  • :count ⇒ the count to be displayed on the header
  • :see_all_opts ⇒ If passed this would create a see all link with this options('See All' link options can be referred above)
  • :pagination_opts ⇒ The pagination options needed to be passed to will_paginate as mentioned above.

The code that renders content of the panel should be passed as a block to this method.

Sample implementation can be found at - app/views/users/recently_shared/_index.html.haml and at - app/views/users/comments_made/_index.html.haml

Used to expand and collapse large amount of text.

Usage:

= truncate_words_with_more_link(text, number_of_words_to_display_initially)

User profile image with chat status

Usage:

= avatar_for(user, options) 

Options:

  • :size - Can be :thumb, :medium, :large (default is :medium)
  • :show_chat_status - True/false. Indicates whether to show the chat status icon or not (default is false)

Inline Popup

Usage:

= link_to_popup(name, options)

Options:

  • :id - ID of the popup
  • :show_expander - True/false. Setting true will show a small arrow next to the link which indicates whether the popup was expanded or collapsed. (Default is true)
  • :remote - A hash that represents all the options that are valid for remote_function.
  • :header_text - Text that will be shown as header of the popup
  • :popup_direction - The direction where the popup will show. Can be :up, :down, :left or :right (default is :down)
  • :padding - True/false. If set to true then the padding will be placed between the popup inner borders and the actual content of the popup.
  • :color - Color of the inner panel of the popup (Default is 'white')
  • :actions - Array of html elements that will appear in the bottom of the popup along side the “Close” button. Ususally this can be a “Save” button that might submit the contents of the popup.
  • :width - The width of popup. Should be an integer value i.e. specify 200 and not 200px

Note: To programatically close the popup use the close_popup(id) helper method. Id here is the ID that is specified in the link_to_popup call.

Custom scrollbar

Usage:

- scrollable_content(options) do
  = some scrollable html here 
  = some html here 

Options:

  • :id - ID of the main container
  • :height - Height after which the scrollbars should appear

Display of rating stars

Usage:

stars(value, size, color)

Arguments:

  • value - The value of the rating. A numeric value.
  • size - Can be 'large' or 'small'. Default is 'small'
  • color - Can be 'orange' or 'yellow'. Default is 'yellow'

Usage:

 = chat_link(from, to)

Both from and to should be objects of User model.

The links like “Follow”, “Like”, “Bookmark”, “Share” can be obtained by following helper methods. All the methods take the object which has to be worked upon as a parameter. e.g. in case of “Like” pass object of comment for liking a comment, pass an object of user for liking a user etc…

  • following_for(followable)
  • liking_for(likeable)
  • bookmark_for(bookmarkable)
  • share_link(shareable)

Flash for ajax calls

To display the flash UI for ajax calls use

  • flash_notice - To display notice message
  • flash_warning - To display warning or error message

Usage:

In the action's render section do something like below

render :update do |page|
  if(success)
    page << flash_notice("Yes done")
  else
    page << flash_warning("Nop")
  end
end
view_helpers.txt · Last modified: 2018/08/31 16:16 (external edit)