Created
April 9, 2011 00:47
-
-
Save danielnegri/910984 to your computer and use it in GitHub Desktop.
Model de Events
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
<%= form_for(@event) do |f| %> | |
<div class="field"> | |
<%= f.label :show_me_as %><br /> | |
<%= f.radio_button :show_me_as, "available" %> | |
<%= f.radio_button :show_me_as, "busy" %> | |
</div> |
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 Event < ActiveRecord::Base | |
# Associations | |
belongs_to :user | |
has_many :reminders, :through => :event_reminders | |
# Validations | |
SHOW_AS_AVAILABLE = 'available' | |
SHOW_AS_BUSY = 'busy' | |
validates_presence_of :title, :begin_at, :end_at | |
validates_length_of :title, :minimum => 3 | |
validates_inclusion_of :show_as, :in => [SHOW_AS_AVAILABLE, SHOW_AS_BUSY] | |
# Scopes | |
scope :not_deleted, where(:deleted_at => nil) | |
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
class InitialSchema < ActiveRecord::Migration | |
def self.up | |
# Events | |
create_table :events do |t| | |
t.references :user, :null => false | |
t.string :title | |
t.datetime :begin_at, :null => false | |
t.datetime :end_at, :null => false | |
t.string :location | |
t.text :description | |
t.string :show_as, :default => 'busy' | |
t.string :privacy, :default => 'private' | |
t.datetime :deleted_at | |
t.timestamps | |
end | |
add_index :events, :user_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Qual é a melhor forma para criar constantes, utilizá-las em campos selecionáveis e traduzi-las com locales (i18n)?