Commit e5ab9ef
Changed files (5)
app
controllers
views
gyms
spec
controllers
app/controllers/gyms_controller.rb
@@ -2,4 +2,9 @@ class GymsController < ApplicationController
def index
@gyms = Gym.closest_to(current_session.location)
end
+
+ def new
+ @gym = Gym.new
+ @gym.build_location
+ end
end
app/views/gyms/new.html.erb
@@ -0,0 +1,26 @@
+<% content_for(:title) do %>
+ <%= t(".title") %>
+<% end %>
+
+<div class="row">
+ <div class="large-12 columns">
+ <h1><%= t(".title") %></h1>
+ <%= form_for(@gym) do |form| %>
+ <%= form.label :name %>
+ <%= form.text_field :name %>
+ <%= form.fields_for :location do |location_form| %>
+ <%= location_form.label :address %>
+ <%= location_form.text_field :address %>
+ <%= location_form.label :city %>
+ <%= location_form.text_field :city %>
+ <%= location_form.label :region %>
+ <%= location_form.text_field :region %>
+ <%= location_form.label :country %>
+ <%= location_form.text_field :country %>
+ <%= location_form.label :postal_code %>
+ <%= location_form.text_field :postal_code %>
+ <% end %>
+ <%= form.submit %>
+ <% end %>
+ </div>
+</div>
config/locales/en.yml
@@ -35,6 +35,8 @@ en:
index:
title: Gyms
view_map: View map
+ new:
+ title: New Gym
registrations:
new:
username: "Username"
config/routes.rb
@@ -10,7 +10,7 @@ Rails.application.routes.draw do
end
resources :programs, only: [:show]
resources :profiles, only: [:new, :create, :show, :edit, :update], constraints: { id: /[^\/]+/ }
- resources :gyms, only: [:index]
+ resources :gyms, only: [:index, :new]
get "/u/:id" => "profiles#show", constraints: { id: /[^\/]+/ }
get "/dashboard" => "training_sessions#index", as: :dashboard
get "/terms" => "static_pages#terms"
spec/controllers/gyms_controller_spec.rb
@@ -18,4 +18,13 @@ describe GymsController do
expect(response).to be_ok
end
end
+
+ describe "#new" do
+ it 'loads the new page' do
+ get :new
+ expect(response).to be_ok
+ expect(assigns(:gym)).to be_instance_of(Gym)
+ expect(assigns(:gym).location).to be_present
+ end
+ end
end