-
-
Save regedarek/ccbef8a0fb67a164efee to your computer and use it in GitHub Desktop.
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
-content_for :title, "Edycja danych osbowych studenta / absolwenta" | |
= simple_form_for @student, html: { multipart: true, class: 'form-horizontal' } do |f| | |
= hidden_field_tag "before_action", "edit" | |
%legend Dane osobowe | |
.row | |
.span7.well | |
= f.input :first_name | |
= f.input :last_name | |
= f.input :email, disabled: true | |
= f.input :birthdate | |
.span4.form-help | |
= t('private_data_help') | |
.row | |
.span7.well | |
= f.input :address_number | |
= f.input :address_street | |
= f.input :address_postalcode | |
= f.input :phone | |
.span4.form-help | |
Lalalala | |
.row | |
.span7.well | |
= f.input :authentication_token, disabled: true | |
.span4.form-help | |
Jest to ten sam klucz który otrzymałeś w wiadomości email. Możesz go skopiować i używać do logowania. | |
.form-actions | |
= f.button :submit, class: "btn btn-primary pull-right" |
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 Student < ActiveRecord::Base | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :confirmable, :registerable, | |
# :lockable, :timeoutable and :omniauthable, :recoverable, :rememberable | |
devise :database_authenticatable, :trackable, :validatable, | |
:token_authenticatable | |
# Accessible (or protected) attributes | |
# | |
attr_accessible :email, :remember_me, | |
:address_number, :address_postalcode, :address_street, :birthdate, :email, | |
:first_name, :last_name, :phone, :educations_attributes, :other_faculties, | |
:other_faculties_english, :english_level, :ask_counter | |
has_many :cvs | |
has_many :educations | |
accepts_nested_attributes_for :educations, | |
:reject_if => lambda { |e| e[:faculty_id].blank? }, | |
allow_destroy: true | |
validates :first_name, | |
on: :update, | |
presence: true | |
validates :last_name, | |
on: :update, | |
presence: true | |
validates :email, | |
on: :update, | |
presence: true | |
validates :birthdate, | |
on: :update, | |
presence: true | |
validates :address_number, | |
on: :update, | |
presence: true | |
validates :address_street, | |
on: :update, | |
presence: true | |
validates :address_postalcode, | |
on: :update, | |
presence: true | |
validates :phone, | |
on: :update, | |
presence: true | |
validates :authentication_token, | |
on: :update, | |
presence: true | |
scope :approved, where(approved: true) | |
before_save :ensure_authentication_token | |
after_create :send_auth_token | |
# after_create | |
def send_auth_token | |
StudentMailer.send_auth_token(self).deliver | |
end | |
# Increase when visit cvs#show | |
def increase_ask_counter | |
update_column(:ask_counter, (ask_counter + 1)) | |
end | |
def cvs_views_counter | |
if cvs.empty? | |
0 | |
else | |
cvs.map(&:views_counter).inject(0, :+) | |
end | |
end | |
def notify_about_contact_request(employer) | |
StudentMailer.notify_about_contact_request(self, employer).deliver | |
end | |
def asked_for_me(employer) | |
increase_ask_counter | |
notify_about_contact_request(employer) | |
employer.send_student_contact(self) | |
end | |
end | |
# == Schema Information | |
# | |
# Table name: students | |
# | |
# address_number :string(255) | |
# address_postalcode :string(255) | |
# address_street :string(255) | |
# approved :boolean default(FALSE), not null | |
# ask_counter :integer default(0) | |
# authentication_token :string(255) | |
# birthdate :date | |
# created_at :datetime not null | |
# current_sign_in_at :datetime | |
# current_sign_in_ip :string(255) | |
# email :string(255) default(""), not null | |
# encrypted_password :string(255) default(""), not null | |
# english_level :integer | |
# first_name :string(255) | |
# id :integer not null, primary key | |
# last_name :string(255) | |
# last_sign_in_at :datetime | |
# last_sign_in_ip :string(255) | |
# other_faculties :text | |
# other_faculties_english :text | |
# phone :string(255) | |
# sign_in_count :integer default(0) | |
# updated_at :datetime not null | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment