gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 5.0
Befehl ausführen
$ bundle install
Fix scss
"App / Assets / Stylesheets / application.css" wurde in "App / Assets / Stylesheets / application.css.scss" geändert.
app/assets/stylesheets/application.css.scss
@import 'bootstrap-sprockets';
@import 'bootstrap';
/* universal */
body {
  padding: 60px 15px 0;
}
Ändern Sie die js-Datei
app/assets/javascript/application.js
//= require bootstrap-sprockets
Container zuordnen
app/views/layouts/application.html.erb
<body>
    <div class='container'>
        <%= yield %>
    </div>
</body>
app/views/shops/index.html.erb
<table class='table table-striped table-hover'>
・ ・ ・
</table>
Fügen Sie dem Link eine Schaltfläche hinzu
app/views/shops/index.html.erb
<%= link_to 'New Shop', new_shop_path, class: 'btn btn-primary' %> | <%= link_to 'Show category list', categories_path %>
Formularänderung
app/views/shops/_form.html.erb
<%= form_for(shop, html: {class: 'form-horizontal', role: 'form'}) do |f| %>
app/views/shops/_form.html.erb
<div class='form-group'>
  <%= f.label :category_id, class: 'col-sm-2 control-label' %>
  <div class='col-sm-10'>
    <%= f.select :category_id, Category.all.map{|o| [o.name, o.id]} %>
  </div>
</div>
<div class='form-group'>
  <%= f.label :name, class: 'col-sm-2 control-label' %>
  <div class='col-sm-10'>
    <%= f.text_field :name %>
  </div>
</div>
<div class='form-group'>
  <%= f.label :address, class: 'col-sm-2 control-label' %>
  <div class='col-sm-10'>
    <%= f.text_field :address %>
  </div>
</div>
app/views/shops/_form.html.erb
<div class='actions'>
  <div class='form-group'>
    <div class='col-sm-offset-2 col-sm-10'>
      <%= f.submit 'Submit', class: 'btn btn-success' %>
    </div>
  </div>
</div>
Gitterbreitenverhältnis </ b> Ordnen Sie die Elemente an, auf die "col-sm-3" angewendet wird, und die Elemente, auf die "col-sm-9" angewendet wird. → Das Breitenverhältnis beträgt 3: 9
app/views/layouts/application.html.erb
<!-- Fixed navbar -->
<nav class='navbar navbar-inverse navbar-fixed-top'>
  <div class='container'>
    <div class='navbar-header'>
      <button type='button' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#navbar' aria-expanded='false' aria-controls='navbar'>
        <span class='sr-only'>Toggle navigation</span>
        <span class='icon-bar'></span>
        <span class='icon-bar'></span>
        <span class='icon-bar'></span>
      </button>
      <%= link_to 'Lunch Map', root_path, class: 'navbar-brand' %>
    </div>
    <div id='navbar' class='collapse navbar-collapse'>
      <ul class='nav navbar-nav'>
       <li><%= link_to 'Shop', shops_path %></li>
       <li><%= link_to 'Category', categories_path %></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>
Klicken Sie auf eine Zeile in der Liste, um die Detailseite anzuzeigen
app/views/shops/index.html.erb
<td><%= link_to shop.category.name, shop, class: 'widelink' %></td>
<td><%= link_to shop.name, shop, class: 'widelink' %></td>
<td><%= link_to shop.address, shop, class: 'widelink' %></td>
app/assets/stylesheets/application.css.scss
/* table row for link */
a.widelink {
   display: block;
   width: 100%;
   height: 100%;
   text-decoration: none;
}
Entfernen Sie jede Listenschaltfläche aus der Liste
app/views/shops/index.html.erb
<table class='table table-striped table-hover'>
  <thead>
    <tr>
      <th>Category</th>
      <th>Name</th>
      <th>Address</th>
    </tr>
  </thead>
Passen Sie die Karte auf dem Bildschirm an
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: '100%',
    height: 320,
    frameborder: 0) %>
Schaltfläche zur Detailseite hinzugefügt
app/views/shops/show.html.erb
<%= link_to 'Delete', @shop,
                    method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %>
<%= link_to 'Edit', edit_shop_path(@shop), class: 'btn btn-primary' %>
<%= link_to 'Back', shops_path, class: 'btn btn-default' %>
Es wurde eine Schaltfläche hinzugefügt, um zur Registrierungsseite zurückzukehren
app/views/shops/_form.html.erb
<div class='actions'>
  <div class='form-group'>
    <div class='col-sm-offset-2 col-sm-10'>
      <%= f.submit 'Submit', class: 'btn btn-success' %>
      <%= link_to 'Back', :back, class: 'btn btn-default' %>
    </div>
  </div>
</div>
Neue und aktualisierte Seitenschaltflächen hinzugefügt
app/views/shops/edit.html.erb
<h1>Editing Shop</h1>
<%= render 'form', shop: @shop %>
<!-- <%= link_to 'Show', @shop %> | -->
<!-- <%= link_to 'Back', shops_path %> -->
app/views/shops/new.html.erb
<h1>New Shop</h1>
<%= render 'form', shop: @shop %>
<!-- <%= link_to 'Back', shops_path %> -->
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  before_action :set_locale
  protect_from_forgery with: :exception
  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end
  def default_url_options(options = {})
    { locale: I18n.locale }.merge options
  end
end
Kopieren Sie ja.yml und korrigieren Sie
$ cp -a config/locales/en.yml config/locales/ja.yml
/config/locale/ja.yml
ja:
  hello: "Welt von Hallo, alle zusammen"
Betten Sie Übersetzungsschlüsselwörter auf der Begrüßungsseite ein
app/views/welcome/index.html.erb
<h1>Lunch Map</h1>
<p>Tasty meal on your place!!</p>
<p><%= t('hello') %></p>
<p><%= link_to 'Show shop list', shops_path %></p>
Betten Sie Übersetzungsschlüsselwörter in die Geschäftsliste ein
app/views/shops/index.html.erb
<h1><%= t('shops') %></h1>
<th><%= t('category') %></th>
<th><%= t('name') %></th>
<th><%= t('address') %></th>
Registrieren Sie englische Wörter in en.yml
/config/locale/en.yml
en:
  hello: 'Hello world'
  shops: 'Shops'
  category: 'Category'
  name: 'Name'
  address: 'Address'
Registrieren Sie Japanisch in ja.yml
/config/locale/ja.yaml
ja:
  hello: 'Welt von Hallo, alle zusammen'
  shops: 'Shop-Liste'
  category: 'Kategorie'
  name: 'Speichername'
  address: 'Adresse'
Fügen Sie Daten zu ja.yml für das Formular hinzu
/config/locale/ja.yaml
ja:
  hello: 'Welt von Hallo, alle zusammen'
  shops: 'Shop-Liste'
  category: 'Kategorie'
  name: 'Speichername'
  address: 'Adresse'
  activerecord:
    models:
      shop:Geschäft
    attributes:
      shop:
        category_id:Kategorie
        name:Speichername
        address:Adresse
Recommended Posts