Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

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 3 years have passed since last update.

Ransack sort_link 色の変更の仕方!

Posted at

Ransack sort_linkでclassを指定することでcssを使って、色を変更する方法

ransackでのソート実装は下記URLを参考にしました
Rubyon Rails で検索機能を作ろう(ransack)

変更前の状態

スクリーンショット 2020-12-14 8.34.07.png

変更後の状態

スクリーンショット 2020-12-14 8.34.18.png

上記画像での、リツイート数ソート部分
デフォルトの青色を黒色に変更する!

index.html.erb

<%= sort_link(@q, :tweet_created_at, "投稿日時" ,{ default_order: :desc }, { class: "Editlink" }) %>

application.scss

// リンク色消す
.Editlink {
  text-decoration: none;
  color: #272343;
  &:link {
    text-decoration: none;
    color: #272343;
  }

  &:visited {
    text-decoration: none;
    color: #272343;
  }

  &:hover {
    text-decoration: none;
    color: #272343;
  }

  &:active {
    text-decoration: none;
    color: #272343;
  }

}

<%= sort_link(@q, 並べるカラム名, "リンクに表示する文字" ,{ 並べ方指定}, { Htmlのオプション }) %>
この書き方のhtmlオプション部分にて、classやidを指定すれば、cssを使って好きなようにsort_linkをカスタマイズできる!

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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
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?