# Conditional in Model

**URL:** <https://www.ruby-forum.com/t/conditional-in-model/59135>\
**Category:** Rails\
**Created:** [April 28, 2006, 10:55pm UTC](https://www.ruby-forum.com/t/conditional-in-model/59135 "2006-04-28T22:55:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dabeeeenster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ed655f/32.png) [@dabeeeenster](https://www.ruby-forum.com/u/dabeeeenster)\
**Post date:** [April 28, 2006, 10:55pm UTC](https://www.ruby-forum.com/t/conditional-in-model/59135/1 "2006-04-28T22:55:23Z")

</div>

Hello ~

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

Thx,

–  
Ben R.  
[http://www.benr75.com](http://www.benr75.com)

---

<div class="post-metadata">

**Author:** ![dabeeeenster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ed655f/32.png) [@dabeeeenster](https://www.ruby-forum.com/u/dabeeeenster)\
**Post date:** [April 28, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/conditional-in-model/59135/2 "2006-04-28T23:10:51Z")

</div>

On 4/28/06, Ben R. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![dabeeeenster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ed655f/32.png) [@dabeeeenster](https://www.ruby-forum.com/u/dabeeeenster)\
**Post date:** [April 28, 2006, 11:13pm UTC](https://www.ruby-forum.com/t/conditional-in-model/59135/3 "2006-04-28T23:13:59Z")

</div>

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. 🙂

-Brian

---

<div class="post-metadata">

**Author:** ![dabeeeenster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ed655f/32.png) [@dabeeeenster](https://www.ruby-forum.com/u/dabeeeenster)\
**Post date:** [April 29, 2006, 1:42am UTC](https://www.ruby-forum.com/t/conditional-in-model/59135/4 "2006-04-29T01:42:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dabeeeenster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ed655f/32.png) [@dabeeeenster](https://www.ruby-forum.com/u/dabeeeenster)\
**Post date:** [April 28, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/conditional-in-model/59135/5 "2006-04-28T23:20:10Z")

</div>

> 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](mailto:removed_email_address@domain.invalid) wrote:

> -Brian
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Ben R.  
removed\_email\_address@domain.invalid  
[http://www.benr75.com](http://www.benr75.com)
