Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 465917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:25:34+00:00 2026-05-12T23:25:34+00:00

Let’s say you’re implementing rails app for a snowboard rental store. A given snowboard

  • 0

Let’s say you’re implementing rails app for a snowboard rental store.

A given snowboard can be in one of 3 states:

  1. away for maintenance
  2. available at store X
  3. on loan to customer Y

The company needs to be able to view a rental history for

  • a particular snowboard
  • a particular customer

The rental history needs to include temporal data (e.g. Sally rented snowboard 0123 from Dec. 1, 2009 to Dec. 3 2009).

How would you design your model? Would you have a snowboard table with 4 columns (id, state, customer, store), and copy rows from this table, along with a timestamp, to a snowboard_history table every time the state changes?

Thanks!

(Note: I’m not actually trying to implement a rental store; this was just the simplest analogue I could think of.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:25:34+00:00Added an answer on May 12, 2026 at 11:25 pm

    I would use a pair of plugins to get the job done. Which would use four models. Snowboard, Store, User and Audit.

    acts_as_state_machine and acts_as_audited

    AASM simplifies the state transitions. While auditing creates the history you want.

    The code for Store and User is trivial and acts_as_audited will handle the audits model.

    class Snowboard < ActiveRecord::Base
    
      include AASM
      belongs_to :store
      
    
      aasm_initial_state :unread
      acts_as_audited :only => :state
    
      aasm_state :maintenance
      aasm_state :available
      aasm_state :rented
    
      aasm_event :send_for_repairs do
        transitions :to => :maintenance, :from => [:available]
      end
    
      aasm_event :return_from_repairs do
        transitions :to => :available, :from => [:maintenance]
      end
    
      aasm_event :rent_to_customer do
       transitions :to => :rented, :from => [:available]
      end
    
      aasm_event :returned_by_customer do
        transitions :to => :available, :from => [:rented]
      end
    end
    
    class User < ActiveRecord::Base
      has_many :full_history, :class_name => 'Audit', :as => :user,
       :conditions => {:auditable_type => "Snowboard"}
    end    
    

    Assuming your customer is the current_user during the controller action when state changes that’s all you need.

    To get a snowboard history:

    @snowboard.audits
    

    To get a customer’s rental history:

    @customer.full_history
    

    You might want to create a helper method to shape a customer’s history into something more useful. Maybe something like his:

     def rental_history
        history = []
        outstanding_rentals = {}
        full_history.each do |item|
          id = item.auditable_id
          if rented_at = outstanding_rentals.keys.delete(id)
            history << { 
              :snowboard_id => id, 
              :rental_start => rented_at,
              :rental_end => item.created_at
            }   
          else
            outstanding_rentals[:id] = item.created_at
          end
        end
        history << oustanding_rentals.collect{|key, value| {:snowboard_id => key,  
          :rental_start => value}
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I can call a method like this: core::get() . What is the
Let's say I have a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I've got two tables: one with customer data, one with location data.
Let's consider the following scenario: a function which can generate code colors from white
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let’s say I have a number like 0x448 . In binary this is 0100
Let's say I have a 12-bit Analog to Digital Converter (4096 bins). And let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.