Rails Conference Presentation 2016 - UX, Rails and Awesomeness
Rupicon 2014 useful design patterns in rails
-
Upload
rupicon -
Category
Technology
-
view
252 -
download
1
Transcript of Rupicon 2014 useful design patterns in rails
Challenge- new design is a one step form vs the 3 step
on the old design- save as draft implies no validations- preview will suffer from the new “draft”
feature- publish will invoke validations
SRP- Add Form - to update the model with data- Validation “Contract” - validate the model- Publish Facade- Presenter - to preview the event
Add FormAvdi Grimm describes form objects as boarder guards. They validate and verify that all data coming into the system is correct.
Once the data moves past the checkpoint it is not checked again.
- a single place to handle input coercion- virtus model- validations
Facade“The Facade Pattern is simply a formalization of the idea that if you cannot avoid complexity, then the next best thing to do is to isolate it, to keep it from contaminating your whole system” -- Russ Olsen
- simplifies access to the object being wrapped or the subsystem- opposite to the decorator- they are not meant to hide anything
Facade and Friends- adapters exist to hide the fact that we are stuck using an object
that has the wrong interface- a proxy stands between the user of an object and the object
itself and somehow controls access to the object- decorators add functionality to an object
Validations on steroidsRemember the contract?
What if you want to validate certain contracts at a certain time?
What if you don’t want to validate a contract at a certain point?
- separate the contracts- group them together based on your needs- validate them…?
Validations on steroidsWikipedia says : The composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object
PresenterBordei Cristian
- is a way to keep your view and controller logic as clean as possible by having a Ruby class serve as the interface between your model and the view/controller.
Presenter vs HelperWhy not Helper you say?
- have logic specific to your models that you need encapsulated
- something you can test
- something you can extend
Conclusions
- Facades are fun and easy but are not an excuse for adding features to a subsystem
- If you want to make several types of coffee with different coffee machines, use a composite
- Presenters make you think helpers are like a compliment that you don't want to give, but feel obligated to: "Yeah, I mean, well, you tried, and that's what counts, right?"