gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 5.0
Execute command
$ bundle install
scss fix
Changed "app / assets / stylesheets / application.css" to "app / assets / stylesheets / application.css.scss"
app/assets/stylesheets/application.css.scss
@import 'bootstrap-sprockets';
@import 'bootstrap';
/* universal */
body {
padding: 60px 15px 0;
}
Modify js file
app/assets/javascript/application.js
//= require bootstrap-sprockets
Allocate container
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>
Add a button to the link
app/views/shops/index.html.erb
<%= link_to 'New Shop', new_shop_path, class: 'btn btn-primary' %> | <%= link_to 'Show category list', categories_path %>
Form modification
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>
Grid width ratio </ b> Arrange the elements to which "col-sm-3" is applied and the elements to which "col-sm-9" is applied. → The width ratio is 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>
Click a row in the list to display the details page
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;
}
Remove each list button from the list
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>
Fit the map on the screen
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) %>
Added button to detail page
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' %>
Added a button to return to the registration page
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>
Added new and refresh page buttons
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
Copy ja.yml and fix
$ cp -a config/locales/en.yml config/locales/ja.yml
/config/locale/ja.yml
ja:
hello: "World of Hello, everyone"
Embed translation keywords on the welcome page
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>
Embed translation keywords in the store list
app/views/shops/index.html.erb
<h1><%= t('shops') %></h1>
<th><%= t('category') %></th>
<th><%= t('name') %></th>
<th><%= t('address') %></th>
Register English words in en.yml
/config/locale/en.yml
en:
hello: 'Hello world'
shops: 'Shops'
category: 'Category'
name: 'Name'
address: 'Address'
Register Japanese in ja.yml
/config/locale/ja.yaml
ja:
hello: 'World of Hello, everyone'
shops: 'Shop list'
category: 'category'
name: 'Store name'
address: 'Street address'
Add data to ja.yml for form
/config/locale/ja.yaml
ja:
hello: 'World of Hello, everyone'
shops: 'Shop list'
category: 'category'
name: 'Store name'
address: 'Street address'
activerecord:
models:
shop:shop
attributes:
shop:
category_id:category
name:Store name
address:Street address
Recommended Posts