Created
May 4, 2011 21:24
-
-
Save mhenrixon/956067 to your computer and use it in GitHub Desktop.
active record extensions
This file contains 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
class ActiveRecord::Base | |
def self.has_statuses(*status_names) | |
validates :status, | |
presence: true, | |
inclusion: { in: status_names.to_s} | |
status_names.each do |status_name| | |
scope "all_#{status_name}", where(status: status_name) | |
end | |
status_names.each do |status_name| | |
define_method "#{status_name}?" do | |
status == status_name.to_s | |
end | |
end | |
end | |
end |
This file contains 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
<li class="select optional error" id="order_status_input"> | |
<label for="order_status">Status</label> | |
<select data-validate="true" id="order_status" name="order[status]"> | |
<option value=""></option> | |
<option value="created">Created</option> | |
<option value="in_progress" selected="selected">In Progress</option> | |
<option value="approved">Approved</option> | |
<option value="rejected">Rejected</option> | |
<option value="shipped">Shipped</option> | |
<option value="delivered">Delivered</option> | |
</select> | |
<p class="inline-errors">is not included in the list</p> | |
</li> |
This file contains 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
var edit_order_2 = | |
{ | |
"type":"Formtastic::SemanticFormBuilder", | |
"inline_error_class":"inline-errors", | |
"validators": | |
{ | |
"order[status]": | |
{ | |
"presence": | |
{ | |
"message":"can't be blank" | |
}, | |
"inclusion": | |
{ | |
"message":"is not included in the list", | |
"in":"[ \"created\", \"in_progress\", \"approved\", \"rejected\", \"shipped\", \"delivered\" ]" | |
} | |
} | |
} | |
}; |
This file contains 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
var edit_order_2 = | |
{ | |
"type":"Formtastic::SemanticFormBuilder", | |
"inline_error_class":"inline-errors", | |
"validators": | |
{ | |
"order[status]": | |
{ | |
"presence": | |
{ | |
"message":"can't be blank" | |
}, | |
"inclusion": | |
{ | |
"message":"is not included in the list", | |
"in":"[ :created, :in_progress, :approved, :rejected, :shipped, :delivered ]" | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment