and manipulating business data, and the View is concerned with displaying it, you can think of the Exhibit as standing between them deciding which data to show, and in what order. It may also provide some extra presentation-specific information (such as the specific URLs for related re- sources) which the business model has no knowledge of by itself. — Avdi Grimm
to: • format complex data for user display • define commonly-used representations of an object • mark up attributes with a little semantic HTML — Draper
publication_status if published? "Published at #{published_at}" else "Unpublished" end end ! def published_at object.published_at.strftime("%A, %B %e") end end EXAMPLE
DSL include Reform::Form::ActiveModel ! properties [:first_name, :last_name], on: :user properties [:email, :locale, :age], on: :profile ! model :user, on: :user ! validates :first_name, :last_name, :email, presence: true end
= Forms::UserForm.new(user: User.new, profile: Profile.new) end ! def create if form.validate(params) form.save do |data, map| user = User.create(map[:user]) map[:user_id] = user.id Profile.create(map[:profile]) end else render action: :new end end end
= investment end ! def promoted? valid_promotion_date? and owner_promotable? end ! def owner_promotable? investment.owner.active_for_promotion? end ! def promotion_status case when promoted? :promoted when valid_promotion_date? and !owner_promotable? :pending_for_promotion else :not_promoted end end ! def valid_promotion_date? (investment.promotion_starts_at..investment.promotion_ends_at).cover? Time.now end end
interface and a singular purpose. It provides a common interface for performing complex interactions in a single request and usually represents a business process. — Collective Idea M C V
AuthenticateUser.perform(session_params) ! if result.success? redirect_to result.user else render :new end end ! private def session_params params.require(:session).permit(:email, :password) end end
by Lailson Bandeira on July 26, 2014 as part of the 21st Frevo on Rails Meetup, available at https://speakerdeck.com/lailsonbm. Slides created with Keynote with the fonts Monserrat, Source Sans Pro and Inconsolata. LAILSON BANDEIRA http://lailson.me/ http://github.com/lailsonbm http://facebook.com/guavasoftware