-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cejaramillof/validations_form
Validations form
- Loading branch information
Showing
20 changed files
with
174 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
class VehiclessController < ApplicationController | ||
class VehiclesController < ApplicationController | ||
def new | ||
@user = current_user | ||
@vechicle = Vehicle.new | ||
@vehicle = Vehicle.new | ||
end | ||
|
||
def create | ||
@vehicle = Vehicle.new(vehicle_params) | ||
@vehicle.user_id = current_user.id | ||
if @vehicle.save | ||
flash[:success] = 'Vehicle registered successfully.' redirect_to user vehicles_path(current_user) | ||
flash[:success] = 'Vehicle registered successfully.' | ||
redirect_to user_vehicles_path(current_user) | ||
else | ||
flash[:error] = @vehicle.errors.full_messages.join('.') render 'new' | ||
flash[:error] = @vehicle.errors.full_messages.join('.') | ||
render 'new' | ||
end | ||
end | ||
|
||
def vehicle_params | ||
params.require(:vehicle).permit(:user_id, :model, :year, :vim, :id) | ||
params.require(:vehicle).permit(:user_id, :model, :year, :vin, :id) | ||
end | ||
private :vehicle_params | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class Location < ActiveRecord::Base | ||
has _many :slots | ||
|
||
validates :latitude, numericality: {only_float:true}, presence: true | ||
validates :longitude, numericality: {only_float: true}, presence: true | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
class ParkRecord < ActiveRecord::Base | ||
belongs_to :slot | ||
belongs_to :vehicle | ||
|
||
validates :entry_date, presence: true | ||
|
||
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h2>Register new vehicle</h2> | ||
<h3>New Vehicle for <%= @user.first_name %> <%= @user.last_name %></h3> | ||
<%= form_for @vehicle, url: {action: 'create'} do |form|%> | ||
<div class="field"> | ||
<%= form.label :model, for:'model' %><br /> | ||
<%= form.text_field :model, placeholder: "Modelo", autofocus: true, required: true %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :year %><br /> | ||
<%= form.select :year, (Time.zone.now.year - 100)..(Time.zone.now.year), required: true %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :vin %><br /> | ||
<%= form.text_field :vin, placeholder: "Placa", autofocus: true, required: true %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit "Register Vehicle" %><%= link_to "Cancel", user_vehicles_path(@user) %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
ValidatesTimeliness.setup do |config| | ||
# Extend ORM/ODMs for full support (:active_record included). | ||
config.extend_orms = [ :active_record ] | ||
# | ||
# Default timezone | ||
# config.default_timezone = :utc | ||
# | ||
# Set the dummy date part for a time type values. | ||
# config.dummy_date_for_time_type = [ 2000, 1, 1 ] | ||
# | ||
# Ignore errors when restriction options are evaluated | ||
# config.ignore_restriction_errors = false | ||
# | ||
# Re-display invalid values in date/time selects | ||
# config.enable_date_time_select_extension! | ||
# | ||
# Handle multiparameter date/time values strictly | ||
# config.enable_multiparameter_extension! | ||
# | ||
# Shorthand date and time symbols for restrictions | ||
# config.restriction_shorthand_symbols.update( | ||
# :now => lambda { Time.current }, | ||
# :today => lambda { Date.current } | ||
# ) | ||
# | ||
# Use the plugin date/time parser which is stricter and extendable | ||
# config.use_plugin_parser = false | ||
# | ||
# Add one or more formats making them valid. e.g. add_formats(:date, 'd(st|rd|th) of mmm, yyyy') | ||
# config.parser.add_formats() | ||
# | ||
# Remove one or more formats making them invalid. e.g. remove_formats(:date, 'dd/mm/yyy') | ||
# config.parser.remove_formats() | ||
# | ||
# Change the ambiguous year threshold when parsing a 2 digit year | ||
# config.parser.ambiguous_year_threshold = 30 | ||
# | ||
# Treat ambiguous dates, such as 01/02/1950, as a Non-US date. | ||
# config.parser.remove_us_formats | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
en: | ||
errors: | ||
messages: | ||
invalid_date: "is not a valid date" | ||
invalid_time: "is not a valid time" | ||
invalid_datetime: "is not a valid datetime" | ||
is_at: "must be at %{restriction}" | ||
before: "must be before %{restriction}" | ||
on_or_before: "must be on or before %{restriction}" | ||
after: "must be after %{restriction}" | ||
on_or_after: "must be on or after %{restriction}" | ||
validates_timeliness: | ||
error_value_formats: | ||
date: '%Y-%m-%d' | ||
time: '%H:%M:%S' | ||
datetime: '%Y-%m-%d %H:%M:%S' |
5 changes: 5 additions & 0 deletions
5
db/migrate/20160723010120_remove_date_details_from_park_records.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveDateDetailsFromParkRecords < ActiveRecord::Migration | ||
def change | ||
remove_column :park_records, :date_details, :datetime | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
db/migrate/20160723011450_add_entry_date_exit_date_total_to_park_records.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddEntryDateExitDateTotalToParkRecords < ActiveRecord::Migration | ||
def change | ||
add_column :park_records, :entry_date, :datetime | ||
add_column :park_records, :exit_date, :datetime | ||
add_column :park_records, :total, :float | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
db/migrate/20160725230124_add_max_slots_adress_to_location.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddMaxSlotsAdressToLocation < ActiveRecord::Migration | ||
def change | ||
add_column :locations, :max_slots, :integer | ||
add_column :locations, :adress, :string | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class AddIndexToUsersEmail < ActiveRecord::Migration | ||
def change | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20160725235348_rename_locations_location_latitudeto_latitude.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RenameLocationsLocationLatitudetoLatitude < ActiveRecord::Migration | ||
def change | ||
rename_column :Locations, :location_latitude, :latitude | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20160725235447_rename_locations_location_longitudeto_longitude.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RenameLocationsLocationLongitudetoLongitude < ActiveRecord::Migration | ||
def change | ||
rename_column :Locations, :location_longitude, :longitude | ||
end | ||
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