MVC newbie question


#1

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


#2

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


#3

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

-Drew


#4

Thanks, I got that working just fine.

On 5/8/06, Andrew R. removed_email_address@domain.invalid wrote:


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


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