& happiness decrease ééãåããããšã§ãç§ãã¡ã¯ãã°ãã°ãã¬ãŒã ãæªããŠããŸããŸã âœ£ç£æ§ãšå¹žçŠåºŠã¯äœäžãã our codebase turns into a monster Ruby on Railsã¯ããæªç£ on Railsãã«ãªã£ãŠããŸã
of conventions Make Rails building blocks a part of your toolbox active_model/active_support/zeitwerk 43 RAILS ãç¿åŸãã RAILS ã®èšèšãã¿ãŒã³ãåŠã¶ èŠçŽã®ååãåãâŒãã RAILSã®æ§æèŠçŽ ãããªãã®ããŒã«ããã¯ã¹ã«âŒãã
where(tags_table[:value].eq(tag)) relation.where(tags_subquery.exists) end private def tags_table @tags_arel ||= Arel::Nodes::NamedFunction.new( "json_each", [arel_table[:tags]] ).then do name = Arel.sql(_1.to_sql) Arel::Table.new(name, as: :json_tags) end end def arel_table = self.class.query_model.arel_table end Separated complexity åé¢ãããè€éã
:after define_callbacks :commit, only: :after def save return false unless valid? with_transaction do AfterCommitEverywhere.after_commit { run_callbacks(:commit) } run_callbacks(:save) { submit! } end end def model_name ActiveModel::Name.new(nil, nil, self.class.name.sub(/Form$/, "")) end private def with_transaction(&) = ApplicationRecord.transaction(&) def submit! raise NotImplementedError end end This is how we leverage Rails building blocks ããã¯Railsã®æ§æèŠçŽ ãæŽ»âœ€ãã✠æ³ã
<%= form_for form do |f| %> <%= f.hidden_field :wizard_state %> # ... We can easily add UI only steps, too UIã®ã¿ã®ã¹ãããã ç°¡åã«è¿œå ã§ãã