Skip to content

Instantly share code, notes, and snippets.

View bsimpson's full-sized avatar

Ben Simpson bsimpson

View GitHub Profile
@bsimpson
bsimpson / gist:3019629
Created June 29, 2012 17:58
How to configure settings on an AR model

Intro

I have a Ruby model that needs to have a configuration option passed to it i.e. config/initializers/contact_import.rb define options so that:

ContactImport.import_mapping # => {'csv' => ..., 'csv_row' => ..., etc}

Option 1

Works in production environment, but not in development since classes reload

config/initializers/contact_import.rb

@bsimpson
bsimpson / gist:2312761
Created April 5, 2012 17:40
Error message display

Introduction

Error messages are currently not handled in a consistent manner in Batchdeux's forms. I have modified the field_error_proc method which serves as a global way to change the behavior of form errors. By modifying this, I have given us the option to display errors in several ways:

Demo

git fetch
git checkout bls/23176299_data_validation_errors

Be sure to restart your webserver, as changes have been made to the config/ directory

@bsimpson
bsimpson / gist:2312760
Created April 5, 2012 17:39
Error message display
# Introduction
Error messages are currently not handled in a consistent manner in Batchdeux's forms. I have modified the `field_error_proc` method which serves as a global way to change the behavior of form errors. By modifying this, I have given us the option to display errors in several ways:
# Options
Options can be passed on an individual `:input` basis.
* `suppress_error` - Do not show any inline errors
* `error_before` - Show the label tag before the :input tag