# MVC newbie question

**URL:** <https://www.ruby-forum.com/t/mvc-newbie-question/59911>\
**Category:** Rails\
**Created:** [May 8, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/mvc-newbie-question/59911 "2006-05-08T15:16:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![afg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecc23a/32.png) [@afg](https://www.ruby-forum.com/u/afg)\
**Post date:** [May 8, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/mvc-newbie-question/59911/1 "2006-05-08T15:16:44Z")

</div>

All,

Is it possible for a view to call back to a controller method? If so,  
what is the syntax?

=== details  
I have a list view that I want to filter out inactive rows based on  
several table fields being zero, old, etc.

It would seem I should create a “filtered” method in the controller  
(which I have done).

Then invoke if from the view like:

for row in @rows  
continue if row.filtered

It is not working. ie. filtered is undefined.

## Thanks Greg

Greg F.  
The Norcross Group  
Forensics for the 21st Century

---

<div class="post-metadata">

**Author:** ![afg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecc23a/32.png) [@afg](https://www.ruby-forum.com/u/afg)\
**Post date:** [May 8, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/mvc-newbie-question/59911/2 "2006-05-08T15:30:11Z")

</div>

Greg F. wrote:

> It would seem I should create a “filtered” method in the controller  
> (which I have done).
> 
> Then invoke if from the view like:
> 
> for row in @rows  
> continue if row.filtered
> 
> It is not working. ie. filtered is undefined.

row here is a model, not a controller. Is the method on the Row class ?  
It’ should be if you are asking each individual row “are you filtered”.

If however ‘filtered’ is not supposed to be a per-row method, but  
list-wide… In your “list” action on controller, create a variable,  
this is accessible from the view.

so  
BlahController#list  
@filtered = true

views/blah/list.rhtml

if @filtered …

Des that make sense ?  
Alan

---

<div class="post-metadata">

**Author:** ![afg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecc23a/32.png) [@afg](https://www.ruby-forum.com/u/afg)\
**Post date:** [May 8, 2006, 3:35pm UTC](https://www.ruby-forum.com/t/mvc-newbie-question/59911/3 "2006-05-08T15:35:46Z")

</div>

Greg F. wrote:

> Is it possible for a view to call back to a controller method?

Sure. ActionController::Helpers::ClassMethods.helper\_method():

[http://lnk.nu/api.rubyonrails.org/98s.html](http://lnk.nu/api.rubyonrails.org/98s.html)

-Drew

---

<div class="post-metadata">

**Author:** ![afg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecc23a/32.png) [@afg](https://www.ruby-forum.com/u/afg)\
**Post date:** [May 9, 2006, 12:41am UTC](https://www.ruby-forum.com/t/mvc-newbie-question/59911/4 "2006-05-09T00:41:20Z")

</div>

Thanks, I got that working just fine.

On 5/8/06, Andrew R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

–  
Greg F.  
The Norcross Group  
Forensics for the 21st Century
