Skip to content

Commit

Permalink
new actions
Browse files Browse the repository at this point in the history
  • Loading branch information
twetzel committed Jun 22, 2014
1 parent 8bc78f1 commit 1bbe5e9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/controllers/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def create
flash[:notice] = "Job was created!"
render :create
else
redirect_to root_path, alert: "Job couldn't be created"
flash[:alert] = "Job couldn't be created"
render :new
end
end

Expand Down
34 changes: 34 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,38 @@ def log( stuff = "# # # # # # # # # # # # # # #" )
Rails.logger.info( stuff ) if Rails.env.development?
end


def error_msg( item )
if item.errors.any?
cls = item.class.to_s.parameterize("_")
headline = "Couldn't save #{cls.to_s.titleize}, there are #{item.errors.count} errors!"
msgs = ""
item.errors.each do |key, msg|
if key.to_s.split(".").count > 1
key = key.to_s.split(".")
that = "#{key[0].to_s.titleize}: #{key[1].to_s.titleize}"
else
that = key.to_s.titleize
end
msgs += <<-HTML
<li>#{ icon("arrow-right") } <strong>#{ that }</strong> #{ msg }</li>
HTML
end
html = <<-HTML
<div class="error-box banderole">
<div class="icn">
#{ icon("info-round") }
</div>
<h4>#{ headline }</h4>
<ul>
#{ msgs }
</ul>
</div>
HTML

html.html_safe
end
end


end
5 changes: 4 additions & 1 deletion app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class Address < ActiveRecord::Base

# =====> A S S O Z I A T I O N S <======================================================== #
belongs_to :owner, :polymorphic => true



validates :street, :street_number, :city, :zip, :longitude, :latitude, presence: true

def address
adr = []
adr << street if street.present?
Expand Down
3 changes: 3 additions & 0 deletions app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ class Job < ActiveRecord::Base
has_many :applications, class_name: "Application", foreign_key: :job_id

has_one_address


validates :date, :duration, presence: true

end
2 changes: 2 additions & 0 deletions app/views/jobs/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Book your care
</div>
<div class="body">

<%= error_msg(@job) %>

<div class="row">
<div class="col-sm-4 press">
Expand Down

0 comments on commit 1bbe5e9

Please sign in to comment.