Forum: Ruby on Rails Conditional in Model

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.
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-04-28 22:55
(Received via mailing list)
Hello ~

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

Thx,

--
Ben Reubenstein
http://www.benr75.com
57e939ff00f9df2670a09f417c08da5e?d=identicon&s=25 Josh Knowles (Guest)
on 2006-04-28 23:10
(Received via mailing list)
On 4/28/06, Ben Reubenstein <benr@x-cr.com> 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
7c4087d053eb02d099a17d91ba5e33b5?d=identicon&s=25 Brian Hughes (Guest)
on 2006-04-28 23:13
(Received via mailing list)
On Apr 28, 2006, at 04:54 PM, Ben Reubenstein 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
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-04-28 23:20
(Received via mailing list)
>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 Hughes <brianvh@alum.dartmouth.org> wrote:
>
> -Brian
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben Reubenstein
benr@x-cr.com
http://www.benr75.com
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2006-04-29 01:42
(Received via mailing list)
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
This topic is locked and can not be replied to.