I am trying to user draper gem and looks like I set up just fine, however, when I call method inside my draper method, I get an "undefined method error" Here is what I have done so far.
gem 'draper'
bundle install
rails g decorator MyModel
in my Decorator, I have the follow code.
class TaskDecorator < Draper::Decorator
delegate_all
decorates :task
def dummy
print "Hello World"
end
end
In my controller
# GET /tasks/1
# GET /tasks/1.json
def show
@task = TaskDecorator.find_by(:id => params[:id])
end
My View
<%= @task.dummy %>
Run in the browser, I get the following error
undefined method `dummy' for #<Task:0x007fad7a639d48>
Any idea, what's wrong?
You can also call
decorates_finders
inTaskDecorator
like this:Then you can get your decorated model by calling