Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4.1 – Deeper into Rails Maciej Mensfeld Presented by: Maciej Mensfeld Deeper into Rails mensfeld.pl github.com/mensfeld senior.

Similar presentations


Presentation on theme: "Chapter 4.1 – Deeper into Rails Maciej Mensfeld Presented by: Maciej Mensfeld Deeper into Rails mensfeld.pl github.com/mensfeld senior."— Presentation transcript:

1 Chapter 4.1 – Deeper into Rails Maciej Mensfeld Presented by: Maciej Mensfeld Deeper into Rails maciej@mensfeld.pl mensfeld.pl github.com/mensfeld senior ruby developer@furioustribe.com

2 Maciej Mensfeld Please… …ask me to slow down, if I speak to quickly; …ask me again, if I forget; …ask questions, if anything i say is not clear; …feel free to share your own observations Deeper into Rails Chapter 4.1 – Deeper into Rails

3 Maciej Mensfeld I18n – we speak different languages! Chapter 4.1 – Deeper into Rails 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

4 Maciej Mensfeld I18n – we speak different languages! Chapter 4.1 – Deeper into Rails Application controller:

5 Maciej Mensfeld I18n – we speak different languages! Chapter 4.1 – Deeper into Rails Try it out!

6 Maciej Mensfeld I18n – we speak different languages! Chapter 4.1 – Deeper into Rails Try it out!

7 Maciej Mensfeld I18n – we speak different languages! Chapter 4.1 – Deeper into Rails Workout time! ruby -Itest test/unit/i18n_test.rb

8 Maciej Mensfeld Be RESTful as much as you can be! Chapter 4.1 – Deeper into Rails 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

9 Maciej Mensfeld Be RESTful as much as you can be! Chapter 4.1 – Deeper into Rails Don’t work with different models in one controller! Don’t use non standard actions (unless you really know what you are doing!) Think with resources, not with actions! Use restful routes (resources :users, etc)

10 Maciej Mensfeld Be RESTful as much as you can be! Chapter 4.1 – Deeper into Rails Use scopes and namespaces! Namespaces are good to separate different logic with same controller names (in different modules) Namespacing stuff helps you manage growing projects

11 Maciej Mensfeld plataformatec / Responders Chapter 4.1 – Deeper into Rails Sets the flash based on the controller action and resource status. Installation process: https://github.com/plataformatec/responders

12 Maciej Mensfeld plataformatec / Responders Chapter 4.1 – Deeper into Rails Responders uses the ‘valid?’ method to determine whether or not the object passed to ‘respond_with’ is valid You can also pass a :location parameter to redirect to a specified route

13 Maciej Mensfeld plataformatec / Responders Chapter 4.1 – Deeper into Rails Workout time! Install and use responders for our Post model in our example app (or in your app for a selected model)

14 Maciej Mensfeld Simplecov – Code coverage Chapter 4.1 – Deeper into Rails 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 code coverage in Ruby project is Simplecov The main advantage of running a coverage tool on your test suite is to find areas of your code that are poorly tested.

15 Maciej Mensfeld Simplecov – Code coverage Chapter 4.1 – Deeper into Rails Edit: test_helper.rb ruby -Itest test/unit/user_test.rb View Rails.root/coverage.index.html

16 Maciej Mensfeld Haml + Simple form Chapter 4.1 – Deeper into Rails 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 => bundle install

17 Maciej Mensfeld Haml + Simple form Chapter 4.1 – Deeper into Rails By default Haml uses DIVs Class declaration starts with dot (.class_name) Id declaration starts with hash (#super_id) To create „not DIV” use % (%h2) All Haml elements close automatically You can mix id, class and other attributes! Rich example: %h3.extra#content{:title => ‘Header title’}

18 Maciej Mensfeld Haml + Simple form Chapter 4.1 – Deeper into Rails Workout time! Change your App layout from erb to haml. Change your Post views from erb to haml HTML2HAML converter: http://html2haml.heroku.com/

19 Maciej Mensfeld Haml + Simple form Chapter 4.1 – Deeper into Rails Rails forms made easy 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. https://github.com/plataformatec/simple_form

20 Maciej Mensfeld Haml + Simple form Chapter 4.1 – Deeper into Rails Simple form can be used with erb or haml templates (or with both)

21 Maciej Mensfeld Haml + Simple form Chapter 4.1 – Deeper into Rails Workout time! Change your forms from Rails std forms to simple form https://github.com/plataformatec/simple_form

22 Chapter 4.1 – Deeper into Rails Maciej Mensfeld Live long and prosper! Presented by: Maciej Mensfeld maciej@mensfeld.pl mensfeld.pl github.com/mensfeld


Download ppt "Chapter 4.1 – Deeper into Rails Maciej Mensfeld Presented by: Maciej Mensfeld Deeper into Rails mensfeld.pl github.com/mensfeld senior."

Similar presentations


Ads by Google