More Related Content
Similar to Ror rails 2 (20)
Ror rails 2
- 1. RoR – Rails 2
● Миграции
● Валидация
● Контроллер
● Отображение
● Partial
- 2. Rake таски
● rake db:migrate
● rake db:migrate:rollback
● rake db:migrate:redo
● rake db:migrate:rollback STEP=3
● rake db:migrate:redo STEP=3
● rake db:migrate:up VERSION=xxxxxxxxxxxxx
● rake db:migrate:down VERSION=xxxxxxxxxxxx
- 3. Работа с таблицами
● Операции с таблицами
create_table, drop_table, change_table
● Операции с колонками:
add_column, change_column, change_column_default,
rename_column, remove_column, add_index,
remove_index
● Типы полей:
:primary_key, :string, :text, :integer, :float, :decimal,
:datetime, :timestamp, :time, :date, :binary, :boolean
- 4. Связи между моделями
● belongs_to
● has_one
● has_many
● has_many :through
● has_one :through
● has_and_belongs_to_many
- 5. Валидации
● Валидации проверяются при вызове:
create, create!, save, save!, update, update_attributes,
update_attributes!
● Не проверяются для:
decrement!, decrement_counter, increment!,
increment_counter, toggle!, update_all, update_attribute,
update_counters
● Проверка валидности объекта:
valid? and invalid?
● Получить массив ошибок
entity.errors[:attribute]
- 6. Хелперы
● validates_acceptance_of
● validates_associated
● validates_confirmation_of
<%= text_field :person, :email %>
<%= text_field :person, :email_confirmation %>
● validates_exclusion_of, validates_inclusion_of
validates_exclusion_of :field, :in => [values], :message =>
'message'
● validates_format_of
validates_format_of :field, :with => /Regexp/,
:message => "message"
- 7. Хелперы
● validates_length_of
:minimum, :maximum, :in, :is
● validates_numericality_of (:only_integer => true)
● validates_uniqueness_of (:scope => :attribute)
● validate :validate_method
def validate_method
end
● пр.
- 8. Callbacks
● before_validation
● after_validation
● before_save
● after_save
● before_update
● around_update
● after_update
● before_destroy
● after_destroy
● around_destroy
● around_destroy