Skip to content

Commit

Permalink
[#6] Add basic create action and form to perform a google query
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 14, 2021
1 parent 5a6e2fc commit aac9dcd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'fabrication' # Fabrication generates objects in Ruby. Fabricators are schem
gem 'sidekiq' # background processing for Ruby
gem 'bootsnap', require: false # Reduces boot times through caching; required in config/boot.rb
gem 'i18n-js', '3.5.1' # A library to provide the I18n translations on the Javascript
gem 'httparty' #Makes http fun again! Ain't no party like a httparty, because a httparty don't stop.

# Authentications & Authorizations
gem 'devise' # Authentication solution for Rails with Warden
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ GEM
globalid (0.4.2)
activesupport (>= 4.2.0)
hashdiff (1.0.1)
httparty (0.18.1)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
i18n-js (3.5.1)
Expand Down Expand Up @@ -216,11 +219,15 @@ GEM
mini_mime (>= 0.1.1)
marcel (1.0.1)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
mini_magick (4.11.0)
mini_mime (1.0.3)
mini_portile2 (2.5.3)
minitest (5.14.4)
msgpack (1.4.2)
multi_xml (0.6.0)
multipart-post (2.1.1)
nap (1.1.0)
nio4r (2.5.7)
Expand Down Expand Up @@ -484,6 +491,7 @@ DEPENDENCIES
ffaker
figaro
foreman
httparty
i18n-js (= 3.5.1)
json_matchers
letter_opener
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/keywords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

class KeywordsController < ApplicationController
def index; end

def create
@keyword = params['keyword']
@raw_response = GoogleService::ClientService.query(@keyword)
end
end
4 changes: 4 additions & 0 deletions app/views/keywords/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Result for <%= @keyword %></h1>
<div>
<%= @raw_response.body.html_safe %>
</div>
6 changes: 6 additions & 0 deletions app/views/keywords/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
<h1>Keywords#index</h1>
<p>Find me in app/views/keyword/index.html.erb</p>

<%= form_with url: keywords_path, method: :post do |form| %>
<%= form.label :keyword, "Search for:" %>
<%= form.text_field :keyword %>
<%= form.submit "Search" %>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Rails.application.routes.draw do
root to: 'keywords#index'

resources :keywords, only: :index
resources :keywords, only: [:index, :create]
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end

0 comments on commit aac9dcd

Please sign in to comment.