Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

PIVOTAL LABS
Standup Blog 11/24/2009: Model validations without backing store, Associations to Array, and SSL with AWS

Ask for Help

“How do I create a model without a backing store?”

One way to do this is to use the active-form plugin (or here), which lets you create model objects that support
ActiveRecord Validations but are not backed by database table. Not to be confused with the other ActiveForm, which is a DSL for defining XHTML forms with validation.

TODO

“How do I turn an association into an array?”

You can access the underlying array by using .target or .proxy_target. If you want to cause the association to load all it’s data pass any parameter, for example

blog = Blog.find(:first)
posts = blog.posts(:force_load)

Interesting Things

  • AWS gems log spew and SSL

Noticed that when using the RightScale Amazon Web Services gem that a lot of log output is going to STDOUT. To capture this output specify a logger wherever you create your AWS service object, for example:

development:

RightAws::S3.new(access_key, secret_key, :logger => Logger.new(File.join(File.dirname(__FILE__), '..', '..', 'aws_sqs.log'), 'daily'))

demo/production:

RightAws::S3.new(access_key, secret_key, :logger => Logger.new(File.join(File.dirname(__FILE__), '..', '..', 'aws_sqs.log'), 'monthly'))

To prevent even more warnings from appearing in your log output you can also set the @http.verify_mode as follows:

original:

      @http.use_ssl = true
      ca_file = get_param(:ca_file)
      if ca_file
        @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
        @http.verify_callback = verifyCallbackProc
        @http.ca_file = ca_file
      end

patched:

      @http.use_ssl = true
      ca_file = get_param(:ca_file)
      if ca_file
        @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
        @http.verify_callback = verifyCallbackProc
        @http.ca_file = ca_file
      else
        @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end

Comments
  1. Mark Wilden says:

    Just to clarify, you can pass any “truthy” parameter to an association method to cause it to be loaded. Passing `false` or `nil` wouldn’t work. Some folks like to pass a symbol (usually of their own devising). I like to pass `true`.

  2. What file did you patch for the SSL warnings? I could not find those lines in any file in RightAWS 1.10.0

  3. John Pignata says:

    Jonathan — Check out the right_http_connection gem. In 1.2.4 you can find the except on line 301 in lib/right_http_connection.rb.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *