Conditional in Model


#1

Hello ~

Is there a way to determine within a model which controller/action
instantiated the model?

Thx,


Ben R.
http://www.benr75.com


#2

On 4/28/06, Ben R. removed_email_address@domain.invalid wrote:

Hello ~

Is there a way to determine within a model which controller/action
instantiated the model?

Your models should not be concerend with things like controllers, views,
etc. They should operate independently not even concerned that they are
in
a web-framework (many people use ActiveRecord for CLI apps).

What is it that you are trying to do?

Josh


#3

On Apr 28, 2006, at 04:54 PM, Ben R. wrote:

Is there a way to determine within a model which controller/action
instantiated the model?

This might sound like a stupid question, but why should your model
care? Something asked for a new instance, so that’s what it gives it.

The “outside world” is very frightening to your model, so you
shouldn’t try to teach it about things beyond what it normally
contains. :slight_smile:

-Brian


#4

Ben,

Have you considered saving the model for every stage of the wizard?
Then validate for each post, conditional upon the stage of the wizard
you’re on? You could even capture the last stage the user was at, and
restore them to this page when they return.

I use this technique, and it works very well. I’ve implemented it
with a (currently) 21 page wizard, and this pattern model works very
well.

cheers,
Jodi


#5

Your models should not be concerend with things like controllers,
views, etc. They >should operate independently not even concerned
that they are in a web-framework (many >people use ActiveRecord for
CLI apps).

I agree… However I have run into an instance in a wizard-type flow
where conditional validation would make my controller dryer. I was
considering using acts_as_state for creating different validations as
I change the state of the object, but I do not want to turn my Models
into modules.

Basically, I load up an object and as the wizard progresses more of
the data is added to the object. I considered passing params between
steps, but if a user only goes part of the way through, it would be
nice to have their progress saved when they return.

Maybe I am just not seeing the easy solution on this one…

Thx for everyone’s help,

Ben

On 4/28/06, Brian H. removed_email_address@domain.invalid wrote:

-Brian


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Ben R.
removed_email_address@domain.invalid
http://www.benr75.com