I love Nokogiri for everything XML, HTML and Ruby. I think the library has been in each project of mine for three or four years. Today’s example I read an HTML file from a service and add nodes the tag. This is a basic extension of the Nokogiri documentation, but should help a basic case not illustrated well in the docs. # Fetch a remote asset and translate it to Nokogiri @page = Nokogiri::HTML::Document.parse(remote_asset) @link = @page.css("body") @meta = @page.css("head").css("meta")   # Create a new node and add the attributes @thumb = Nokogiri::XML::Node.new "link", @page @thumb["href"] = "http://application-bucket.s3.amazonaws.com/fancy/css/jquery.thumbs.css" @thumb["type"] = "text/css" @thumb["rel"] = "stylesheet"   # Attach the new node to the page @meta.after(@thumb)   # Assign a new instance[…]

In a classic Rails application it’s typical to have a route similar to this http://localhost:8000/model/1 In the controller this translates to this: def show @model = Model.find(params[:id]) end But in some cases you may want to render something based on a users session. Maybe you have a currently edited file or a profile item you need to bring in. If you have an available session to query on you can do this. def show @model = Model.find_by_url(current_user_session.url) The cool part about this, is now you can have a url in a show action render anything and as long as the session is active the user will only see their active session information. http://localhost:8000/model/anything_you_want :)

Ruby Array has the %w operator for typing out Arrays more quickly. >> normal_arr = ["trout", "broccoli", "vegetables"] => ["trout", "broccoli", "vegetables"]   # The short hand version is this.   >> arr = %w[trout broccoli vegetables] => ["trout", "broccoli", "vegetables"]   # But look what happens if you add the normal Array syntax of quotes and commas   >> arr = %w["trout" "broccoli" "vegetables"] => ["\"trout\"", "\"broccoli\"", "\"vegetables\""]   >> arr = %w["trout", "broccoli", "vegetables"] => ["\"trout\",", "\"broccoli\",", "\"vegetables\""]   # Also note, # it will turn your integers into strings # and give you fishy results if # you try to populate something other than a string   >> a = %w[1 2 3 4 5 ] =>[…]