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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:36:54+00:00 2026-05-24T11:36:54+00:00

Here are my models: class BillingProfile < ActiveRecord::Base belongs_to :student attr_accessible :cost end class

  • 0

Here are my models:

class BillingProfile < ActiveRecord::Base
  belongs_to :student
  attr_accessible :cost
end

class PerEventBillingProfile < BillingProfile
  belongs_to :event_category
end

class FlatFeeBillingProfile < BillingProfile
  attr_accessible :interval, :frequency
end

Students can have many billing profiles of both types. What I’d like is a radio button in my student creation form that lets the user choose between creating a PerEventBillingProfile and a FlatFeeBillingProfile. When the per event radio is chosen, fields for a PerEventBillingProfile would show up, and vice versa. In order to get that to happen with this model setup, it appears I’d have to do:

class Student < ActiveRecord::Base
  has_many :per_event_billing_profiles
  has_many :flat_fee_billing_profiles
  accepts_nested_attributes_for :per_event_billing_profiles
  accepts_nested_attributes_for :flat_fee_billing_profiles
end

It feels like this could be simpler. Is there a more straightforward way to get what I want? I realize that I could stuff all of this into one model and just have a bunch of NULL values in my columns, but I don’t like that either.

  • 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-24T11:36:54+00:00Added an answer on May 24, 2026 at 11:36 am

    Here’s how I got through this. I kept the has_many :billing_profiles line in Student. In the form I did this:

    <%= f.fields_for :billing_profiles do |builder| %>
      <tr>
        <%= render 'billing_profile_fields', :f => builder %>
      <tr>
    <% end %>
    

    And in the partial:

    <td>
      <%= f.label :type, "Profile type" %>
      <%= f.select :type, { "Per Event" => "PerEventBillingProfile", "Flat Fee" => "FlatFeeBillingProfile" } %>
    </td>
    

    And I hide the fields which are irrelevant to the currently selected type using JS. This does mean that all the validations have to go in BillingProfile however, which kinda defeats the purpose of sti.

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

Sidebar

Related Questions

Here are my models: class Deck < ActiveRecord::Base belongs_to :game has_many :deck_cards end class
So I have two models here: class Screen < ActiveRecord::Base belongs_to :user validates :screen_size,
Hi (huge Rails newbie here), I have the following models: class Shop < ActiveRecord::Base
Hey, need a little help here. I have two models: class User < ActiveRecord::Base
Here is my models: class User < ActiveRecord::Base has_one :worker, :class_name => 'Worker', :foreign_key
My models: class NewsItem < ActiveRecord::Base has_many :file_uploads, :as => :uploadable accepts_nested_attributes_for :file_uploads, :allow_destroy
I have these two models class Invoice < ActiveRecord::Base has_many :items accepts_nested_attributes_for :items ...
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =
Here's part of my Django app's models.py : class Person(models.Model): birth_year = WideYear(null=True, blank=True)
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here

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.