Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working version with Geocoder #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'geocoder'
gem 'bootstrap', '~> 5.1.3'
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ GEM
zeitwerk (~> 2.3)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
autoprefixer-rails (10.4.2.0)
execjs (~> 2)
bindex (0.8.1)
bootsnap (1.7.5)
msgpack (~> 1.0)
bootstrap (5.1.3)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.9.3, < 3)
sassc-rails (>= 2.0.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.35.3)
Expand All @@ -79,7 +85,9 @@ GEM
concurrent-ruby (1.1.9)
crass (1.0.6)
erubi (1.10.0)
execjs (2.8.1)
ffi (1.15.1)
geocoder (1.7.3)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.10)
Expand Down Expand Up @@ -107,6 +115,7 @@ GEM
nokogiri (1.11.7-x86_64-linux)
racc (~> 1.4)
pg (1.2.3)
popper_js (2.9.3)
public_suffix (4.0.6)
puma (5.3.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -207,8 +216,10 @@ PLATFORMS

DEPENDENCIES
bootsnap (>= 1.4.4)
bootstrap (~> 5.1.3)
byebug
capybara (>= 3.26)
geocoder
jbuilder (~> 2.7)
listen (~> 3.3)
pg (~> 1.2.3)
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
*= require_tree .
*= require_self
*/

.navbar {
margin-bottom: 20px;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/forecasts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Forecasts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
12 changes: 12 additions & 0 deletions app/controllers/forecasts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ForecastsController < ApplicationController
def index
@address = params[:address]
geocoder_results = Geocoder.search(@address)
if geocoder_results
@latitude, @longitude = geocoder_results.first.coordinates
end
end

def new
end
end
2 changes: 2 additions & 0 deletions app/helpers/forecasts_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ForecastsHelper
end
3 changes: 3 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ import "channels"
Rails.start()
Turbolinks.start()
ActiveStorage.start()

import "bootstrap"
import "../stylesheets/application"
1 change: 1 addition & 0 deletions app/javascript/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "bootstrap"
6 changes: 6 additions & 0 deletions app/views/forecasts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= form_with url: "/forecasts/index", class: 'form-inline', method: :get do |form| %>
<div class="input-group mb-3">
<%= form.text_field :address, class: "form-control", placeholder: "One Apple Park Way, Cupertino, CA 95014", value: @address, "aria-describedby": "button-addon2" %>
<%= form.button :GO, class: "btn btn-outline-secondary", id: "button-addon2"%>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/forecasts/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render "form" %>

2 changes: 2 additions & 0 deletions app/views/forecasts/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<%= render "form" %>
18 changes: 18 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,27 @@

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>

<body>
<header>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container">
<a href="<%=root_url%>" class="navbar-brand d-flex align-items-center">
<strong>Weather Forecast App</strong>
</a>
</div>
</div>
</header>

<div class="container">
<%= yield %>
</div>

<footer>
<div class="navbar-bottom"></div>
</footer>

</body>
</html>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Rails.application.routes.draw do

root "forecasts#new"

get 'forecasts/index'
get 'forecasts/new'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
23 changes: 3 additions & 20 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
const environment = require("./environment");
const { merge } = require("webpack-merge");
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

process.env.NODE_ENV = process.env.NODE_ENV || "development";
const defaultConfig = environment.toWebpackConfig();
const environment = require('./environment')

if (process.env.GITPOD_WORKSPACE_URL) {
const [protocol, hostname] = process.env.GITPOD_WORKSPACE_URL.split("://");

// ex: https://3035-fuchsia-lamprey-16r2m3h5.ws-us14.gitpod.io
const devServerPublic = `https://3035-${hostname}`;

const mergedConfig = merge(defaultConfig, {
devServer: {
public: devServerPublic,
},
});

module.exports = mergedConfig;
} else {
module.exports = defaultConfig;
}
module.exports = environment.toWebpackConfig()
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
"name": "template-ruby-on-rails",
"private": true,
"dependencies": {
"@popperjs/core": "^2.11.2",
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.4.0",
"bootstrap": "^5.1.3",
"turbolinks": "^5.2.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.11.2"
"webpack-dev-server": "^4.7.4"
}
}
13 changes: 13 additions & 0 deletions test/controllers/forecasts_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "test_helper"

class ForecastsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get forecasts_index_url
assert_response :success
end

test "should get new" do
get forecasts_new_url
assert_response :success
end
end
Loading