3
3

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.

Draperでdecorateした元のオブジェクトを参照する

3
Posted at

decorateしたもののメソッド(例えばUser#name)を呼ぼうとしたら、NoMethodErrorと出てきてしまった。

最初の方法

<% (@user.methods - Object.new.methods).each do |method| %>
  <%= method %><br>
<% end %>

で見ると、
user, object, model, source
なるものを発見。どうやらdecorateする元らしい。なので、

user.object.name

とすれば動くようになった。

あとで調べると…

http://qiita.com/tachiba/items/6f0d56598de639adae1d#3-5
https://github.com/drapergem/draper#delegating-methods

を見るに、

class UserDecorator < Draper::Decorator
  delegate_all
end

とすればいいらしい。

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?