Forum: Ruby on Rails Single table inheritance problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Szymon N. (Guest)
on 2006-02-21 21:38
Hi!

Is there anywhere on the net a sample of some basic app (with actions
like create, edit etc.) that uses single table inheritance?

I'm trying to create (my first) app with 2 different types of users and
while it basically works, my code is quite messy.

I.e. i've got 2 forms, each for different type of user. To use the same
rhtml files for creating and editing the user, i need to pass to the
form file @action (which action should be performed on submit) and
@submit_value (text on submit button) parameters and in case of edit
action also pass :id => @user to the action. It must be done in every
action in controller that renders a form.

Would it be better (simpler for sure) to create 2 sets of forms, which
would have all fields identical and only differ in action, id passed to
it and value of the submit button?
Anthony G. (Guest)
on 2006-02-22 17:22
g0nzo  wrote:
> Hi!
>
> Is there anywhere on the net a sample of some basic app (with actions
> like create, edit etc.) that uses single table inheritance?
>
> I'm trying to create (my first) app with 2 different types of users and
> while it basically works, my code is quite messy.
>
> I.e. i've got 2 forms, each for different type of user.

I'd use one form and extend it for user b with a simple if statement.

_T
William L. (Guest)
on 2006-02-22 22:21
> Would it be better (simpler for sure) to create 2 sets of forms, which
> would have all fields identical and only differ in action, id passed to
> it and value of the submit button?

I think it's a matter of style and how much difference there is between
the forms. If the forms are quite different it makes sense to have two
forms as partials and let your layout choose which one to render. If the
forms are similar with a few differences then it makes sense to use one
form and update the needed values dynamically.

In general, I prefer to make my layouts, views, and partials dynamic and
set the necessary attributes in all my actions if necessary. This
provides for better html re-use; which I also find is the biggest pane
to maintain if your not re-using. Second, it encapsulates the
differences between all the views in one location, the controller. This
makes for easier viewing and and easier updating.

my $.02,
  William
This topic is locked and can not be replied to.