Custom validation with rails: words with more than 26 characters
def validate if subject.split.any?{|w| w.length > 26} errors.add(:subject, "cannot have words more than 26 consecutive characters") end end
DZone Snippets > ioda006 > rails
12545 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
def validate if subject.split.any?{|w| w.length > 26} errors.add(:subject, "cannot have words more than 26 consecutive characters") end end
<%= display_categories(@categories) %>
def display_categories(categories)
ret = "<ul>"
for category in categories
if category.parent_id == 0
ret += "<li>"
ret += link_to category.name
ret += find_all_subcategories(category)
ret += "</li>"
end
end
ret += "</ul>"
end
def find_all_subcategories(category)
if category.children.size > 0
ret = '<ul>'
category.children.each { |subcat|
if subcat.children.size > 0
ret += '<li>'
ret += link_to h(subcat.name), :action => 'edit', :id => subcat
ret += find_all_subcategories(subcat)
ret += '</li>'
else
ret += '<li>'
ret += link_to h(subcat.name), :action => 'edit', :id => subcat
ret += '</li>'
end
}
ret += '</ul>'
end
end