$ rails generate scaffold shop category_id:integer name:string address:string
$ rails db:migrate'```
 Association du modèle de grève de catégorie et de liste de magasin
#### **`app/model/category.rb`**
```rb
class Category < ApplicationRecord
  has_many :shops
end
app/models/shop.rb
class Shop < ApplicationRecord
  belongs_to :category
end
Permet de sélectionner une catégorie sur le formulaire d'inscription / modification
app/views/shops/_form.html.erb
<div class="field">
  <%= f.label :category_id %>
  <%= f.select :category_id, Category.all.map{|o| [o.name, o.id]} %>
</div>
Afficher le nom de la catégorie dans l'affichage de la liste et l'affichage détaillé de la liste des magasins
app/view/shops/index.html.erb
<td><%= shop.category.name %></td>
app/view/shops/show.html.erb
app/view/shops/show.html.erb
Ajouter un formulaire de recherche à afficher
/app/views/shops/index.html.erb
<%= form_tag('/shops', method: 'get') do %>
<%= label_tag(:name_key, 'Search name:') %>
<%= text_field_tag(:name_key) %>
<%= submit_tag('Search') %> <%= link_to 'Clear', shops_path %>
<% end %>
<br>
Modifier la méthode d'index dans le contrôleur
/app/controllers/shops_controller.rb
def index
  if params[:name_key]
    @shops = Shop.where('name LIKE ?', "%#{params[:name_key]}%")
  else
    @shops = Shop.all
  end
end
Lien depuis la page d'accueil
app/views/welcome/index.html.erb
<h1>Lunch Map</h1>
<p>Tasty meal on your place!!</p>
<p><%= link_to 'Show shops', shops_path %></p>
 Google Maps API Google Maps API | Google Developers https://developers.google.com/maps/
Google Developers Console https://console.developers.google.com/
Ajouter une zone de carte à afficher
app/views/shops/show.html.erb
<%= content_tag(:iframe,
                'map',
                 src:'https://www.google.com/maps/embed/v1/place?key=AIzaSyCJBgcuCowQa5-V8owXaUCHhUNBN8bfMfU&q=' + @shop.address,
                 width: 800,
                 height: 400,
                 frameborder: 0) %>
<br>
        Recommended Posts