MetaSkills.net

Rails Button Links In Embedded Forms

Posted On: January 5th, 2010 by kencollins

This is one I have had sitting around for almost 3 years now in my toolbox and thought I would share. Have you ever had complicated rails forms and needed simple form buttons that just took you to a simple link? Were you bitten by the button_to helper code because it generates another form inside of a form? If so, here is a simple rails view helper I made that creates simple button links for embedded forms by making an input with a javascript function. Tag soup you ask, hell yeah, but worth if if you need it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

def button_to_link(name, link, options={})
  confirm_option = options.delete(:confirm)
  popup_option = options.delete(:popup)
  link_function = popup_option ? redirect_function(link,:new_window => true) : redirect_function(link)
  link_function = "if (confirm('#{escape_javascript(confirm_option)}')) { #{link_function}; }" if confirm_option
  button_to_function name, link_function, options
end

def redirect_function(location, options={})
  location = location.is_a?(String) ? location : url_for(location)
  if options[:new_window]
    %|window.open('#{location}')|
  else
    %|{window.location.href='#{location}'}|
  end
end
Tags: form, rails, ruby

Authenticated S3 GETs For Private Objects Using Paperclip

Posted On: November 23rd, 2009 by kencollins

Yea I know, I am probably the last person on earth that is just getting around to using Paperclip. To be honest, most of my file upload code was written way before Paperclip or even AttachementFu was ever conceived. And frankly, I do not do much social app coding on the side - so the need never came up. But that changed recently and I wanted a really really good way of leveraging AWS::S3 storage with the best local app security while maintaining tight control over the files.

Tags: paperclip, rails, ruby, s3

Installing REE With The Snow Leopard SQL Server Stack

Posted On: October 27th, 2009 by kencollins

Today I noticed that Ruby Enterprise Edition 2009.10 was released and I have really been wanting to see if I could get the SQL Server adapter tested and running under it. I am really curious how the speed improvements might look and will share my results below. This article assumes that you read my previous guide titled The Ultimate OS X Snow Leopard Stack For Rails Development - x86_64, MacPorts, Ruby 1.8/1.9, SQL Server, SQLite3, MySQL & More as I will be building on top of it and referencing certain steps. So let's get down to business.

Tags: ree, ruby, sqlserver

The Zombie Shotgun Revisited

Posted On: October 10th, 2009 by kencollins
Resident Evil Zombie Shotgun

My how time flies. Over a year ago I created a simple bit of code that was useful for stopping ActionController routing errors from common Microsoft attacks from sending exception notification emails. Well now most people do not use exception notifications emails in favor of apps like Hoptoad. And hey, most code like this has moved to Rack middlewares.

Yesterday I noticed a rack code competition that encouraged "most useful and top quality Rack middlewares". Well the Zombie Shotgun is pretty useful to me, but I'm sure it's not top quality. That said, I did take the time to finally pick up on the rack internals and learn how to use rack-test. If you want to check out the new tested Zombie Shotgun middleware and how I tested it using Shoulda, go see the project on my github page. Also, here is my CodeRack entry.

Tags: middleware, rack, ruby

The Ultimate OS X Snow Leopard Stack For Rails Development - x86_64, MacPorts, Ruby 1.8/1.9, SQL Server, SQLite3, MySQL & More

Posted On: September 5th, 2009 by kencollins

This guide is all encompassing but primarily focuses on the benefits of MacPorts, second the development stack for SQL Server and lastly on anything else a rails developer might need on OS X. If you are on a Mac, possibly running Snow Leopard and x86_64 is near and dear to your heart, this article is for you. If you do not "have" to use SQL Server, you can safely skip those sections and get to the Ruby1.9/Apache2/SQLite3/MySQL stuff.

757rb Memcached Talk

Posted On: July 18th, 2009 by kencollins

757.rb Memcached Presentation Earlier this week I gave a talk at our local ruby users group, 757.rb, about Memcached. Here recently I started picking it up again so that I could keep track of large sets of PK/FK changes during a big database move. In doing so, I decided to dig deep into it's internals and get a better grasp of how I would use it when I decided to do some serious fragment caching again.

PDF::Writer For Ruby 1.9

Posted On: May 14th, 2009 by kencollins

If you have legacy code written for ruby 1.8 and you want to run 1.9 and support your old PDF::Writer code, then just jump right over to my Github pdf-writer fork and get it.

sudo gem install metaskills-pdf-writer

If you are interested in knowing some of the dirty details about what pitfalls are under 1.9, read on. The biggest thing for me was getting used to the character encodings. Including string literals in your code that are say UTF-8 or some other encoding will blow up on you real quick. I highly highly suggest that you read James Edward Gray II: Everything About Ruby 1.9 Character Encoding Series series. He covers all the basics. If you want to see what two commits I did for pdf-writer, see here and here. The second one is very very hackish, it basically add a marshaling support to the Mutex class which 1.9 does not have. The reason this is needed was due to pdf-writer's use of transaction simple to roll back object state as it is drawing across multiple pages. If you are like me and wish all your PDF::Writer code was in Prawn, your not alone!

Resources

Tags: 1.9, pdf, ruby, writer