Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created February 2, 2012 13:17
Show Gist options
  • Save Amitesh/1723426 to your computer and use it in GitHub Desktop.
Save Amitesh/1723426 to your computer and use it in GitHub Desktop.
Tableless model with validation
# http://rails-bestpractices.com/posts/48-use-openstruct-when-advance-search
class Tableless
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(props = {})
props.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
class Search < Tableless
validates :quick, :presence => true
end
def index
@search = Search.new(params[:search])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment