Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Arthur Miller
Courses Plus Student 7,487 PointsDecorators
In the adding social features course, the decorators lesson does not seem to be working at all. I get totally different file headers that do not work with the code presented after installing the gem 'draper' running the bundle install command and using bin/rails generate decorator user_friendship. What I get it the file with a header of: class UserFriendshipDecorator < Draper::Decorator delegate_all
and: require 'test_helper' class UserFriendshipDecoratorTest < Draper::TestCase
I have tried to use the presented code anyway, but it does not work. Then I tried to replace the different code with all of the code presented, which does not work either.
Being new at this, I could use some help.
1 Answer
Ralph Robot
217 PointsI'm unfamiliar with that particular Treehouse course, but do have experience with decorators. I have written about decorator implementations in Ruby and have tried the Draper gem, but decided to avoid it.
Using Draper results in technically better object-oriented programming and makes it easier to obey Tell, Don’t Ask. However, it blurs the lines of MVC, introduces a permanent Parallel Hierarchy problem, and increases the already high prevalence of Shotgun Surgery in Rails app.
It’s a theoretical improvement that results in higher maintenance and obscurity in the real world. I avoid it unless I'm facing serious problems with view helpers, which is what Draper replaces.