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 4010498
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:00:28+00:00 2026-05-20T09:00:28+00:00

My setup: Rails 2.3.10, Ruby 1.8.7 I would like some feedback on where it

  • 0

My setup: Rails 2.3.10, Ruby 1.8.7

I would like some feedback on where it is best to put logic code, and REST API, that touches multiple models in a single transaction. For example, a user needs to buy a product, it’ll involve

  1. Checks if he has sufficient money (user model)
  2. Check if the product is available (product model)
  3. Calculate shipping charge (zipcode, product models)
  4. Subtract money
  5. Update product availability count
  6. …

You get the general idea. Let’s say I need to provide a buy REST API, which controller should it go in? And where should the actual logic go? Should it be in the model associated with the controller? Appreciate any insights.

  • 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-20T09:00:29+00:00Added an answer on May 20, 2026 at 9:00 am

    I don’t know what the convention is (if there is one), but I tend to do my multi-model transactions in a “noun-verb” format. For example, if a User wanted to purchase a Product, I would do:

    class User < ActiveRecord::Base
      ...
      def purchase(product)
        product.logic
        self.step_3_profit
        etc
      end
    end
    

    The controller works similarly, although I usually think about it in passive voice (e.g., “what verb is being done to what noun”, rather than “what noun is doing what verb”. For example, if a Product was being purchased, it might be a POST to /products/1/purchase, with the following controller code:

    class ProductsController < ApplicationController
      include SessionsHelper
    
      def purchase
        current_user.purchase Product.find(params[:id])
        do_view_stuff
      end
    end
    

    Using these “conventions”, I can easily locate the logic in my app by thinking about what verb is being done to what noun.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My setup: Rails 2.3.10, Ruby 1.8.7 I would like to add a database table
I would like to use Kdevelep as a Ruby on Rails IDE as I'm
Im doing a ruby on rails project for work and they would like to
I am running Ruby on Rails 3 and I would like to set up
Rails 3.0.10, Ruby 1.9.2, ActiveSupport::TestCase I would like to print to STDOUT the log
The Setup I have a Ruby on Rails application that I manage from a
I'm trying to get Ruby on Rails setup on my new eeeubuntu install and
I've been trying to get setup with Ruby on Rails today, but I think
I've set up a new Rails 2.3.2 app and added the Basecamp API ruby
I want to setup a rails app on heroku that is part of a

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.