1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アプリケーション作成で詰まった箇所

Last updated at Posted at 2020-02-27

環境

Ruby 2.6.5
Rails 5.2.4
Docker 19.03.5
bundler 2.1.4

bundler問題

別途記事

フラッシュメッセージ

表示される

user_sessions_controller.rb
redirect_back_or_to root_url, success: 'ログインしました'

表示されない

user_sessions_controller.rb
redirect_to root_path, success: 'ログアウトしました'

解決法

application_controller.rb
# 追加
add_flash_types :danger, :success, :warning

原因

調査中
そもそもadd_flash_typesの指定がないとBootstrapに対応したsuccess info warning danger の4つのキーが使用できないはずなのにredirect_back_ro_toだと表示されるのは4つのキーがデフォルトで備わっているからなのか?

文字コードがlatin1による文字化け

データベース内で文字化けするだけであって、取り出して使用する場合は文字化けしないのでとりあえず放置。

jQueryのclickイベントでdocument使用時のみ発火しない

試したこと

turbolinksが原因か?

Gemfile.lockからturbolinks削除
application.jsから読み込み削除
application.html.slimから読み込み削除
参考資料

docker-compose bundle update
docker-compose build
・コンテナの再起動
→変わらず

原因

調査中
remote: true & application.jsの//= require rails-ujs

remote: trueで送信するとrails-ujsのjQueryがなんかしてるっぽくclickイベントが使用できない。

解決法

remote: trueをやめるかclickイベントをやめる。
今回はclickイベントを使用せず実装する。

ransackで関連付けしたモデルからも検索をかけたい

postsテーブルのtitle、body、tagsテーブルのtagの3つのカラムから検索をかけたい。

原因

join 関連付けの検索ワードが出てこず若干詰まったこと

解決法

訂正前

= f.search_field :title_or_body_or_cont, class: "form-control mr-sm-2", placeholder: '検索ワード'

訂正後

= f.search_field :title_or_body_or_tags_tag_cont_any, class: "form-control mr-sm-2", placeholder: '検索ワード'

関連付けしてあることが前提!

active_link_toがroot_pathが絡むとうまく動作しない

原因

リンク先にrootが絡むとactive_link_toがうまく動作しないようです。
参考記事

解決法

li.nav-item
  = active_link_to admin_root_path, class: "nav-link", active: [['admin/users'], ['index','edit','show']] do
    i.fas.fa-user.mr-3
    p
      |  ユーザー一覧

activeにしたいコントローラ/アクションを記載active: [[コントローラ名], [アクション名]]
例:active: [['admin/users'], ['index','edit','show']]
ネストしてある場合は親も記述。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?