rootの設定と共通テンプレートの設定
rootの設定
#09 rootの設定をしよう | Ruby on Rails 4入門 - プログラミングならドットインストール
projects#indexがルートに表示されるように
routes.rb
# You can have the root of your site routed with "root" # root 'welcome#index'
routes.rb
Rails.application.routes.draw do resources :projects root 'projects#index'
プロジェクト一覧の画面がホーム画面に設定されてます。
共通テンプレートの設定
#10 共通テンプレートを編集しよう | Ruby on Rails 4入門 - プログラミングならドットインストール
画像を設置します。
どの画面でも共通にするためにapp>views>layouts>application.html.erb
に記述します。
<!DOCTYPE html> <html> <head> <title>Taskapp</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html>
<%= yield %>にviewの内容が反映される。
app>assets>images
に画像を入れておいた上で、<body>
タグ内に記述します。
<body> <%= image_tag "myicon2_s.jpg" %> <%= yield %> </body>
共通のスタイルシート設定
app>assets>stylesheets>application.css
背景色をグレーにします。
/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any styles * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * *= require_tree . *= require_self */ body { background: #eee; }
画像設置と、背景色がグレーに設定されています。
Homeへのリンクを張る
これも共通テンプレート内に記述
application.html.erb
<%= link_to "Home", projects_path %>
リンク先は$ rake routes
で見た時の
projects GET /projects(.:format) projects#index
projects_pathで/projectsへのパスになる。
/projectsをrootに設定したので、まあ表示は同じ