Rails - ビュー
Railsでtypeahead.jsを使ったオートコンプリート機能(入力補完機能)の実装手順 https://www.virment.com/rails-typeahead-autocomplete/ typeahead.jsのGithub https://github.com/twitter/typeahead.js/ 実装例 http://twitter.github.io/typeahead.js/ex…
content_tagメモ before <div class="alert alert-<%= message_type %>"><%= message %></div> after <%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
パーシャルにオブジェクトの複数形を渡し、見やすいコードにする 基本の使い方 collectionオプションにより、コレクションのメンバごとにパーシャルをレンダリングする <%= render partial: "product", collection: @products %> 具体的な使い方 Before Refa…
基本的な書き方と、自身がハマったところ 基本的な書き方 公式 sass-lang.com日本語かもーんぬの場合はこちら ferret-plus.com 親を参照する場合 例えば、:hoverとかの場合 通常のCSS #logo { float: left; color: #fff; } #logo:hover { color: #fff; text-…
<%= link_to image_tag("sample.png", alt: "Sampleの写真"), root_path %>
gemを入れることですぐにできる。Bootstrap3か4を使うかで利用するgemが異なる。Bootstrap3:bootstrap-sass gem Bootstrap4:bootstrap gem Bootstrap3を導入する Gemfile gem 'bootstrap-sass', '~> 3.3.7' gem 'sass-rails', '>= 3.2' app/assets/stylesh…
なぜlocalsで渡す必要があるのか インスタンス変数を直接使うと、Viewと特定のControllerとの依存が強まり、別の箇所で再利用しにくくなるため。 悪い例 Controller (良い例と同じ) class UsersController < ApplicationController def show @user = User.fi…