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?

viewでクラスメソッド使えるじゃん・・・!

Posted at

Overview

緊急で動画回してますw
今日たまたま開発していて気づいた大発見でしたので、共有です。
タイトルの通りなのですが、、、

Context

これまではなんとなく、クラスメソッドはControllerに書いちゃっていました。
(いや、modelにかけよっていう感じですが)

なぜか、これまでviewでクラスメソッドを使うっていう発想がなかったのですが、今回間違えて書いてしまったら動いちゃった感じです。

でも、viewにロジックを書くのは絶対良くないと思います。
とはいえ、何かしら用途はあるはずなので、特定の条件下では便利そうな気づきでした

Get Started!!

これまで

# UserController
def index
  @users = User.all
end
<%= @users.each do |user| %>
.
.

直接viewにかける

これまで

<%= User.all.each do |user| %>
.
.
0
0
3

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?