Thank, ROR got too many option, this is why some people don't like it, personally i think that ROR is the most robust an complete MVC pattern software. Thank to DRIFTING RUBY for maintain updated
Yup. Programmers do that often. If you haven't watched "Object oriented programming is bad" by Brian Will, I highly recommend it. As for RoR, it's probably better that you just write some simple conversion logic (we're talking like
4:00 you actually don't need to prepend @model if you inherit from SimpleDelegator and call super(@model). Great video, but it would be even better if you didn't take the leap with the Delegator and shown why just a class without delegating would be inconvenient
Well explained, but I still have a question. Wouldn't it be better to just import all of the helpers inside ApplicationPresenter and don't provide a view context on every presenters initalization because it's ruining DRY by not allowing to use this presenter in other cases, different to view render, like sending an email or creating an PDF with invoice, etc ?????
Very nice explained but I think you can even create without initializing presenter following is simplified version. ``` class UserPresenter < SimpleDelegator include ActionView::Helpers::NumberHelper def full_name "#{first_name} #{last_name}" end def birth_year return nill unless birthdate birthdate.year end def nickel_per_year return nil unless birthdate difference = Date.today.year - birth_year number_to_currency(difference * 0.05) end end```
@@DriftingRuby Thanks.... explaining things like these are the steps that are often missed in tutorials, and which made Railscasts the gold standard. Your tutorials are also very good (except when you start renaming things without explanation :p )
Thank, ROR got too many option, this is why some people don't like it, personally i think that ROR is the most robust an complete MVC pattern software. Thank to DRIFTING RUBY for maintain updated
Great explanation! Thanks!
Can anyone explain why "super(@model)" is needed in UserPresenter class ?
Cool!
I'm fairly new too rails, but I'm struggling to see how this is a better way of doing things. Seems like it's obfuscating code, with out much benefit.
Yup. Programmers do that often. If you haven't watched "Object oriented programming is bad" by Brian Will, I highly recommend it. As for RoR, it's probably better that you just write some simple conversion logic (we're talking like
Make sense, thank you! But wouldn't it be nice to have this kind of functionality wrapped in a gem like for draper?
4:00 you actually don't need to prepend @model if you inherit from SimpleDelegator and call super(@model). Great video, but it would be even better if you didn't take the leap with the Delegator and shown why just a class without delegating would be inconvenient
Well explained, but I still have a question. Wouldn't it be better to just import all of the helpers inside ApplicationPresenter and don't provide a view context on every presenters initalization because it's ruining DRY by not allowing to use this presenter in other cases, different to view render, like sending an email or creating an PDF with invoice, etc ?????
Very nice explained but I think you can even create without initializing presenter following is simplified version.
```
class UserPresenter < SimpleDelegator
include ActionView::Helpers::NumberHelper
def full_name
"#{first_name} #{last_name}"
end
def birth_year
return nill unless birthdate
birthdate.year
end
def nickel_per_year
return nil unless birthdate
difference = Date.today.year - birth_year
number_to_currency(difference * 0.05)
end
end```
great until the 7 minute mark, wtf is a Klass?
class is a reserved keyword in ruby, so some will use klass instead when defining a variable which points to a Class.
@@DriftingRuby Thanks.... explaining things like these are the steps that are often missed in tutorials, and which made Railscasts the gold standard. Your tutorials are also very good (except when you start renaming things without explanation :p )