0
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.

tagヘルパーについて

0
Last updated at Posted at 2019-05-05

例えば、ヘルパーモジュールにhtmltタグを戻り値とするメソッドを作成したかったことがあったため、
その時にrailsのtagヘルパーを使ったので、シェアします。

前提

Rails:5.1.4
ruby:ruby 2.6.0p0

使い方

tag.(タグ名) "タグ内のテキスト" [, 追加したい属性] ※スペースなど注意必要
こちらを参照:Ruby on Rails API

例

tag.a "hoge", class: "test" , type: "button", data: {toggle: "modal", target: "#1"}

と記載すると、返されるhtmlタグは、下記のようになる。

<a class="test" type="button" data-toggle="modal" data-target="#1">hoge</a>

data属性の書き方がポイントです!

0
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
0
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?