“strive 8/7 ~ 8/13”
Use
-
[Gem] virtus
-
[Gem] sorcery
- authentication for Rails
-
[Gem] capybara-webkit
- A Capybara driver for headless WebKit to test JavaScript web apps
-
[Gem] capybara
- Acceptance test framework for web applications
-
[Gem] database_cleaner
- Strategies for cleaning databases
-
[Gem] temping
- model mockup, dynamic create db table for model test
-
[Gem] rubycritic
- provide a quality report of your Ruby code.
-
[Gem] CapistranoDeployTest
- Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma
-
[Gem] meta-tags
- make your Rails application SEO-friendly
-
[Gem] friendly_id
- for pretty url
-
[Gem] sitemap_generator
- create sitemap
-
[SEO] BROWSEO
- see how search engine read your website
-
[Gem] sphinx
- full-text search engine
Read
-
[Ruby] ActionController::Metal#performed?
- you can test whether render or redirect already happended
-
[Ruby] ActiveModel::Validations#valid?(context=nil)
- validates_length_of :slug, minimum: 3, on: :user
- validates_length_of :slug, minimum: 1, on: :admin
- @user.save(context: :admin), @user.valid?(:admin), @user.valid?(:user),
-
[Ruby] 7-ways-to-decompose-fat-activerecord-models
- Value Objects: define domain-specific Value Objects, Value Objects are great when you have an attribute or small group of attributes that have logic associated with them
- Service Objects: action is complex, action reaches across multiple models, action interacts with an external service, action is not a core concern of the underlying model
- Form Objects: Virtus, When multiple ActiveRecord models might be updated by a single form submission, a Form Object can encapsulate the aggregation
- Query Objects: For complex SQL queries littering the definition of your ActiveRecord subclass
- View Objects: If logic is needed purely for display purposes, it does not belong in the model.
- Policy Objects: Sometimes complex read operations might deserve their own objects * “Service Object” for write operations and “Policy Object” for reads, Query Objects focus on executing SQL to return a result set
- Decorators: For cases where callback logic only needs to run in some circumstances or including it in the model would give the model too many responsibilities, a Decorator is useful
-
[Ruby] Configuring database_cleaner with Rails, RSpec, Capybara, and Selenium
- different cleaner strategy settings
-
[Ruby] routing constraints
-
[Ruby] How to use rails routing constraints
- security vulnerabilities and data type validation
- encapsulate and simplify actions (and supporting code)
-
[Ruby] composed_of
- model representing attributes as value objects
-
[SEO] 給 Rails Developer 的基本SEO
Book
-
- done (1), (2)
-
- rails api design
-
-
Refactoring recipes
- Inline controller filters
- extract filter to service
- Explicitly render views with locals
- pass the params to partials explicitly with render
- Extract render/redirect methods
- extract a private method for each render and redirect call
- Extract a Single Action Controller class
- extract like CreateProductsController only when ProductsController is too too too large
- Extract routing constraint
- use routing constraint to seperate controller action
- Extract an adapter object
- extract call external library to adapter object call
- Extract a repository object
- hide the direct ActiveRecord calls, isolated, add data storage on repo object
- Extract a service object using the SimpleDelegator
- move some domain or business logic to service object
- Extract conditional validation into Service Object
- when validation only used in one place, drop the condition on model, move it to service object
- Extract a form object
- move form to form object, more explicit and domain is expressed better
- form object can’t have save method (SRP), Persistence is a seperate concern and different object should take care of it, form object only valid data
- Inline controller filters
-
Patterns
-
Instantiating service objects *
-
The repository pattern *
- Wrap external API with an adapter
- isolated our interface from the implementation
-
4 ways to early return from a rails controller
- extracted_method; return if performed?
-
Service::Input *
-
Validations: Contexts *
- Validations: Objectify *
-
-
Related topics
- Service controller communication
- True/false; return the object created/updated; return a response object that contains all the data and/or errors;
- carry data through exceptions; controller passes callback methods;
- Where to keep services
- group your services according to the feature and then surround them with proper namespace
- ex: Reporting::MonthlyReport, Forum::CreateNewTopic, TimeTracking::LogTimeService
- Routing constraints
- use routing constraints for situations where you need to choose differentctions based on some params
- This makes the controller thinner and it’s more explicit what actios happening
- Service controller communication
-