Created
February 2, 2012 13:17
-
-
Save Amitesh/1723426 to your computer and use it in GitHub Desktop.
Tableless model with validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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