Skip to content

Instantly share code, notes, and snippets.

@danielnegri
Created April 9, 2011 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielnegri/910984 to your computer and use it in GitHub Desktop.
Save danielnegri/910984 to your computer and use it in GitHub Desktop.
Model de Events
<%= 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>
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
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
@danielnegri
Copy link
Author

Qual é a melhor forma para criar constantes, utilizá-las em campos selecionáveis e traduzi-las com locales (i18n)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment