Skip to content

Instantly share code, notes, and snippets.

@edzhelyov
Created March 7, 2012 13:05
Show Gist options
  • Save edzhelyov/1992995 to your computer and use it in GitHub Desktop.
Save edzhelyov/1992995 to your computer and use it in GitHub Desktop.
Search helper
class Search
class NotUrlHelperPresent < Exception; end
attr_writer :url_helper
def url(params)
raise NotUrlHelperPresent unless @url_helper
@url_helper.call(params)
end
end
# Usage example:
search = Search.new :brokers
seearch.url_helper = method(:brokers_path)
# and in the template:
<%= search.url(:search => search.to_hash) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment