Module: Ramaze::Helper::Search

Defined in:
lib/zen/helper/search.rb

Overview

The Search helper is a helper that can be used in controllers allowing the user to search the content of those controllers and models.

Since:

Instance Method Summary (collapse)

Instance Method Details

- (String) render_search_form(url)

Renders a search form that points to the given URL.

Parameters:

  • url (#to_s)

    The URL to point the search form to.

Returns:

  • (String)

Since:

  • 16-10-2011



17
18
19
20
21
22
# File 'lib/zen/helper/search.rb', line 17

def render_search_form(url)
  render_file(
    __DIR__('../view/search.xhtml'),
    :url => url.to_s
  )
end

- (NilClass|Mixed) search

Calls the given block used to search a number of records. If the search action raises an error a message is displayed and the user will be redirected back to the previous page.

If no search query is specified nil will be returned.

Examples:

results = search do |query|
  Sections::Model::Section.search(query)
end

Returns:

  • (NilClass|Mixed)

Since:

  • 16-10-2011



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zen/helper/search.rb', line 39

def search
  if request.params['query'].nil? or request.params['query'].empty?
    return nil
  end

  begin
    return yield(request.params['query'])
  rescue => e
    Ramaze::Log.error(e.inspect)
    message(:error, lang('zen_general.errors.invalid_search'))
    redirect_referrer(::Sections::Controller::Sections.r(:index))
  end
end