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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:00:40+00:00 2026-05-13T09:00:40+00:00

In a toy Rails application, I’m modelling a situation where you have a number

  • 0

In a toy Rails application, I’m modelling a situation where you have a number of pots, each containing an amount of something, and you can make transactions between the pots. A transaction can come from any pot, and go to any pot.

Here are the relevant parts of the models:

class Pot < ActiveRecord::Base
  has_many :to_transactions, :foreign_key => "to_id", :class_name => "Transaction"
  has_many :from_transactions, :foreign_key => "from_id", :class_name => "Transaction"
end

class Transaction < ActiveRecord::Base
  belongs_to :to_pot, :class_name => "Pot", :foreign_key => "to_id"
  belongs_to :from_pot, :class_name => "Pot", :foreign_key => "from_id"
end

This allows me to do the following at the console:

>> p = Pot.find(123)
>> p.from_transactions
=> # returns array of transactions from pot 123
>> t = p.to_transactions.new
=> # t is a new transaction with to_id set to 123

and so on.

I’m having a problem setting up the routing. For example, I would like:

  • /pots/123/from_transactions to give a list of all transactions from pot 123,
  • /pots/123/to_transactions/new to give the new transaction form, with the to_id set to 123

Is this possible? Any help gratefully received etc etc.

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

    My routes.rb now includes the following:

    map.resources :transactions, :path_prefix => '/pots/:from_id', :as => :from_transactions
    map.resources :transactions, :path_prefix => '/pots/:to_id', :as => :to_transactions
    

    This means, for example, that a request to /pots/123/from_transactions/new is sent to the transactions controller, and params[:from_id] is set to 123.

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

Sidebar

Related Questions

I have a toy facebook app I'm playing with so I can understand how
I have been making a little toy web application in C# along the lines
A toy-case for my problem: I have a numpy array of size, say, 1000:
I have some toy code for a tooltip. It works okay, except that when
Here's my toy setup. I have 3 tables. One table is a guest list
Small toy app can be found here: http://gist.github.com/517445 I am trying to send artificial
Just as a toy, I'm using the iTunes SDK and XNA to make my
I started on a little toy project in C lately and have been scratching
I am building a toy Rails app. I generated a scaffold for my Post
Suppose we have a (toy) C++ class such as the following: class Foo {

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.