Skip to content

Instantly share code, notes, and snippets.

@Ameeda
Ameeda / NokogiriXPathNamespaces
Created May 5, 2011 14:48
Selecting elements in some namespace using Nokogiri with XPath
2 ways to extract elements from within XML namespaces using Nokogiri
When trying to select elemenets in the default namespace, e.g. "xmlns= http://www.w3.org/2005/Atom", try the following two ways. Note the xmlns=" attribute on entry element:
Original xml:
Nokogiri::XML(@xml_string).xpath("//author/name").each do |node|
puts node
end
1. Define a namespace context for your XPath expression and point your XPath steps to match elements in that namespace. Define a namespace-to-prefix mapping and use this prefix (a) in the XPath expression.
@Ameeda
Ameeda / gist:947147
Created April 28, 2011 19:38
TIPS for using Form Helpers
Based on my e-mail discussion with SNUGGS & reading Rails Guides, here are some helpful tips to keep in mind when using form helpers:
-First define the input elements you want/need as well as the functional purpose of including them.
-Then, pick the helper that best serves that goal.
Examples:
- When I want to accept a string for my object it's usually a textbox.
- When that information is pretty lengthy (e.g. paragraphs) I probably need a textarea.
- When I want to restrict a selection group to one I'd probably use a radiobutton
- When I want to have multiple selections within a selection group I probably want a checkbox