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.

form画面内のselectでcollection一覧を分かりやすくする

Posted at

普通にDraperでdecoratorを適用するだけど忘れそうなのでメモ

app/decorators/tag_decorator.rb
class TagDecorator < ApplicationDecorator
  def name
    "id:#{object.id} <#{object.text_ja}>"
  end
end

app/admin/post_decorator.rb
form do |f|
  ...
  f.input :tag,
    collection: TagDecorater.decoreate_collection(Tag.all)
  ...
end

もちろんCollectionに対してDecoratorを作っておく方法でも良い

         
class TagsDecorator < Draper::CollectionDecorator
  def page_number
    42
  end
end
--- 
   
TagsDecorater.decoreate(Tag.all)

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?