Last active
March 27, 2016 21:38
-
-
Save jonahgeorge/9b024883ee873281e115 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
<%= form_for @form do |f| %> | |
<div class="row"> | |
<div class="col-sm-6"> | |
<div class="form-group"> | |
<%= f.label :name %> | |
<%= f.text_field :name, class: "form-control", placeholder: "Keep it clean...", required: true %> | |
</div> | |
<div class="form-group"> | |
<%= f.label :label %> | |
<%= f.number_field :label, class: "form-control", required: true %> | |
</div> | |
<div class="form-group"> | |
<%= f.label :user_id, "Setter" %> | |
<%= f.select :user_id, @setters.collect {|p| [ p.name, p.id ] }, {}, class: "form-control", required: true %> | |
</div> | |
<div class="form-group"> | |
<%= f.label :grade %> | |
<%= f.select :grade, Route.grades.keys, { include_blank: true }, class: "form-control", required: true %> | |
</div> | |
</div> | |
<div class="col-sm-6"> | |
<div class="form-group"> | |
<%= f.label :location %> | |
<%= f.select :location, Route.locations.keys, { include_blank: true }, class: "form-control", required: true %> | |
</div> | |
<div class="form-group"> | |
<%= f.label :route_set_date, "Date Set" %> | |
<%#= f.text_field :route_set_date, class: "form-control", required: true %> | |
<%= f.date_field :route_set_date, class: "form-control", required: true %> | |
<%#= f.date_field :route_set_date, class: "form-control", required: true, value: (@route.route_set_date || Date.today) %> | |
</div> | |
<!-- | |
NOTE: consider making a migration to change 'tape_color' to 'color' in the db. since some | |
gyms may not use tape, but just the holds themselves. | |
--> | |
<div class="form-group"> | |
<%= f.label :tape_color, "Color" %> | |
<%= f.text_field :tape_color, class: "form-control", placeholder: "Red, Blue, etc...", required: true %> | |
</div> | |
</div> | |
</div> | |
<br> | |
<div class="row"> | |
<div class="col-sm-6"> | |
<div class="form-group"> | |
<%= f.label :image_1, "Image #1" %> | |
<%= f.file_field :image_1, class: 'form-control' %> | |
<%#= f.file_field :image_1, class: 'form-control', required: true %> | |
</div> | |
</div> | |
<div class="col-sm-6"> | |
<div class="form-group"> | |
<%= f.label :image_2, "Image #2" %> | |
<%= f.file_field :image_2, class: 'form-control' %> | |
<%#= f.file_field :image_2, class: 'form-control', required: true %> | |
</div> | |
</div> | |
</div> | |
<br> | |
<div class="form-group"> | |
<%= f.submit nil, class: "btn btn-primary" %> | |
</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
require "reform/form/validation/unique_validator.rb" | |
class RouteForm < Reform::Form | |
include Reform::Form::ActiveModel | |
include Reform::Form::ActiveModel::FormBuilderMethods | |
property :name | |
property :user_id | |
property :label | |
property :location | |
property :tape_color | |
property :route_set_date, format: :date | |
property :status | |
property :grade | |
property :image_1 | |
property :image_2 | |
validates :name, presence: true | |
validates :user_id, presence: true | |
validates :label, presence: true, unique: true | |
validates :location, presence: true | |
validates :tape_color, presence: true | |
validates :route_set_date, presence: true | |
validates :status, presence: true | |
validates :grade, presence: true | |
def route_set_date | |
super || Date.today | |
end | |
# validates :image_1, presence: true | |
# validates :image_2, 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
class RoutesController < ApplicationController | |
def new | |
@form = RouteForm.new(Route.new) | |
end | |
def create | |
@form = RouteForm.new(Route.new) | |
if @form.validate(route_params) | |
@form.save | |
flash[:success] = "Successfully created route listing." | |
redirect_to action: :index | |
else | |
render :new | |
end | |
end | |
private | |
def route_params | |
params.require(:route).permit(:name, :user_id, :label, :location, :tape_color, :grade, :route_set_date, :image_1, :image_2) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment