・ Rubis: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ Système d'exploitation: macOS Catalina
Ce qui suit a été mis en œuvre.
・ Présentation mince ・ Introduction de Bootstrap 3
Gemfile
gem 'acts-as-taggable-on'
Gemfile
$ bundle
Terminal
$ rails acts_as_taggable_on_engine:install:migrations
Terminal
$ rails db:migrate
schema.rb
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.string "taggable_type"
t.integer "taggable_id"
t.string "tagger_type"
t.integer "tagger_id"
t.string "context", limit: 128
t.datetime "created_at"
t.index ["context"], name: "index_taggings_on_context"
t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
t.index ["tag_id"], name: "index_taggings_on_tag_id"
t.index ["taggable_id", "taggable_type", "context"], name: "taggings_taggable_context_idx"
t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
end
create_table "tags", force: :cascade do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "taggings_count", default: 0
t.index ["name"], name: "index_tags_on_name", unique: true
end
book.rb
#Postscript
acts_as_taggable
Ajoutez tag_list
au paramètre strong.
books_controller.rb
def book_params
params.require(:book).permit(:title, :body, :tag_list)
end
slim:books/new.html.slim
/Postscript
= f.label :tag_list, 'marque'
br
= f.text_field :tag_list, value: @book.tag_list.join(','), id: 'tags'
br
tag_list.join(',')
➡︎ Vous pouvez ajouter plusieurs balises en les séparant par des virgules (,).
slim:books/index.html.slim
/Postscript
td
- book.tag_list.each do |tag|
span.label.label-default style='margin-right: 10px;'
= tag
** ① Accédez au lien ci-dessous ** tag-it GitHub
** ② Cliquez sur "Cloner ou télécharger" **
** ③ Cliquez sur Télécharger ZIP
**
** ④ Déplacer le fichier **
Décompressez le fichier téléchargé.
Placez jquery.tagit.css
et tagit.ui-zendesk.css
dans le dossier css
sous ʻassets / stylesheets`.
Placez tag-it.js
dans le dossier js
sous ʻassets / javascripts`.
Gemfile
gem 'jquery-ui-rails'
Terminal
$ bundle
application.js
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require jquery
//= require jquery-ui //Postscript
//= require bootstrap-sprockets
//= require tag-it
//= require_tree .
application.scss
/*
*= require_tree .
*= require jquery.tagit //Postscript
*= require tagit.ui-zendesk //Postscript
*= require_self
*/
Recommended Posts