220 likes | 388 Views
Chapter 4.1 – Deeper into Rails. Deeper into Rails. Presented b y :. Maciej Mensfeld. senior ruby developer@furioustribe.com. maciej@mensfeld.pl mensfeld.pl github.com / mensfeld. Maciej Mensfeld. Chapter 4.1 – Deeper into Rails. Deeper into Rails. Please ….
E N D
Chapter 4.1 – DeeperintoRails DeeperintoRails Presented by: Maciej Mensfeld senior rubydeveloper@furioustribe.com maciej@mensfeld.pl mensfeld.pl github.com/mensfeld Maciej Mensfeld
Chapter 4.1 – DeeperintoRails DeeperintoRails Please… • …ask me to slow down, if I speak to quickly; • …ask me again, if I forget; • …askquestions, ifanything i sayis not clear; • …feelfree to shareyourownobservations Maciej Mensfeld
Chapter 4.1 – DeeperintoRails I18n – we speakdifferentlanguages! I18n - Easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application. Every static string in the Rails framework — e.g. Active Record validation messages, time and date formats — has been internationalized You may be tempted to store the chosen locale in a session or a cookie. Do not do so. The locale should be transparent and a part of the URL. This way you don’t break people’s basic assumptions about the web itself: if you send a URL of some page to a http://guides.rubyonrails.org/i18n.html Maciej Mensfeld
Chapter 4.1 – DeeperintoRails I18n – we speakdifferentlanguages! Applicationcontroller: Maciej Mensfeld
Chapter 4.1 – DeeperintoRails I18n – we speakdifferentlanguages! Tryit out! Maciej Mensfeld
Chapter 4.1 – DeeperintoRails I18n – we speakdifferentlanguages! Tryit out! Maciej Mensfeld
Chapter 4.1 – DeeperintoRails I18n – we speakdifferentlanguages! Workout time! ruby -Itest test/unit/i18n_test.rb Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Be RESTful as much as youcan be! Representational State Transfer Representational State Transfer (REST) is a style of software architecture for distributed systems such as the World Wide Web. • Scalability of component interactions • Generality of interfaces • Independent deployment of components • Intermediary components to reduce latency, enforce security and encapsulate legacy systems Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Be RESTful as much as youcan be! Don’tworkwithdifferentmodelsin one controller! Don’tuse non standard actions (unlessyoureallyknowwhatyouaredoing!) Thinkwith resources, not withactions! Userestfulroutes (resources :users, etc) Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Be RESTful as much as youcan be! Usescopes and namespaces! Namespacesaregood to separatedifferentlogicwith same controllernames(in differentmodules) Namespacingstuffhelpsyoumanagegrowingprojects Maciej Mensfeld
Chapter 4.1 – DeeperintoRails plataformatec / Responders https://github.com/plataformatec/responders Sets the flash based on the controller action and resource status. Installationprocess: Maciej Mensfeld
Chapter 4.1 – DeeperintoRails plataformatec / Responders Respondersusesthe ‘valid?’ method to determinewhetheror not theobjectpassed to ‘respond_with’ isvalid Youcanalso pass a :locationparameter to redirect to a specifiedroute Maciej Mensfeld
Chapter 4.1 – DeeperintoRails plataformatec / Responders Workout time! Install and useresponders for our Post model inourexampleapp(orinyourapp for a selected model) Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Simplecov – Codecoverage Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. Primary gem for codecoveragein Ruby projectisSimplecov The main advantage of running a coverage tool on your test suite is to find areas of your code that are poorly tested. Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Simplecov – Codecoverage Edit: test_helper.rb ruby -Itest test/unit/user_test.rb ViewRails.root/coverage.index.html Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Haml + Simple form Haml (HTML abstraction markup language) is based on one primary principle: markup should be beautiful. It’s not just beauty for beauty’s sake either; Haml accelerates and simplifies template creation down to veritable haiku. gem ‘haml’ # Gemfile=> bundleinstall Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Haml + Simple form By defaultHamlusesDIVs Classdeclarationstartswithdot (.class_name) Id declarationstartswithhash (#super_id) To create „not DIV” use % (%h2) All Hamlelementscloseautomatically Youcan mix id, class and otherattributes! Richexample: %h3.extra#content{:title => ‘Headertitle’} Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Haml + Simple form Workout time! ChangeyourApplayoutfrom erb to haml. Changeyour Post viewsfrom erb to haml HTML2HAML converter: http://html2haml.heroku.com/ Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Haml + Simple form SimpleForm aims to be as flexible as possible while helping you with powerful components to create your forms. The basic goal of SimpleForm is to not touch your way of defining the layout, letting you find the better design for your eyes. Rails forms made easy https://github.com/plataformatec/simple_form Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Haml + Simple form Simple form can be usedwith erb orhamltemplates(orwithboth) Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Haml + Simple form Workout time! ChangeyourformsfromRailsstdforms to simple form https://github.com/plataformatec/simple_form Maciej Mensfeld
Chapter 4.1 – DeeperintoRails Live long and prosper! Presented by: Maciej Mensfeld maciej@mensfeld.pl mensfeld.pl github.com/mensfeld Maciej Mensfeld