Created
November 27, 2011 16:18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def markdown(text) | |
options = [:hard_wrap, :filter_html, :autolink] | |
Redcarpet.new(text, *options).to_html.html_safe | |
end | |
# Use within views to set the page's HTML title | |
def title(title = nil) | |
default = "" | |
if title | |
content_for(:title) { title } | |
else | |
content_for?(:title) ? content_for(:title) : default | |
end | |
end | |
# Use within views to set the page's HTML meta description | |
def description(text) | |
content_for(:description) { text } | |
end | |
# Displays all flash messages in appropriately named divs for easy styling | |
def flash_messages | |
messages = flash.keys.collect { |key| flash_message(key, flash[key]) } | |
content_tag(:div, messages.to_s.html_safe, :id => "flash-messages") | |
end | |
# Format a single flash message | |
def flash_message(type, message) | |
content_tag(:div, :class => "flash-message #{type.to_s}") do | |
content_tag :p, message | |
end | |
end | |
def inherited_path(resource, action, text=action) | |
resource.type ||= Post | |
if action == "show" | |
return link_to text, "#{resource.type.to_s.downcase}s/#{resource.title}".to_s | |
elsif action == "edit" | |
return link_to text, "#{resource.type.to_s.downcase}s/#{resource.title}edit".to_s | |
elsif action == "destroy" | |
if text == 'destroy' | |
text = 'delete' | |
end | |
return link_to text, "#{resource.type.to_s.downcase}s/#{resource.title}".to_s, method: :delete, confirm: "Are you sure?" | |
else | |
return "post_resource_path(resource_object, action, link_text)" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment