Can a action view invoke a methode of a controller then display its results

Hi,

Can an action view (a template) invoke a methode of a controller, then
display the results of the methode at the same template?

like:
if actionTwo return a simple string "xyz123"

and the action view looks like this:

<body>
   abcde
  <%= render(:action => :actionTwo) %>
</body>

Should the result html be
abcde
xyz123

Thanks you very much

Sayoyo

You can call a method on the controller by:

@controller.method_call

so

<%= render(:action => @controller.actionTwo) %>

I think that will work. Not tested though.

-andy

···

On 11/8/05, sayoyo@yahoo.com <sayoyo@yahoo.com> wrote:

Hi,

Can an action view (a template) invoke a methode of a controller, then
display the results of the methode at the same template?

like:
if actionTwo return a simple string "xyz123"

and the action view looks like this:

<body>
abcde
<%= render(:action => :actionTwo) %>
</body>

Should the result html be
abcde
xyz123

Thanks you very much

Sayoyo

--
Andrew Stone

Hi,

I have tried the @controller.actionTwo, but it doesn't work. I got the
following msg error:

You have a nil object when you didn't expect it!
The error occured while evaluating nil.actionTwo

I think, it doesn't recognize the contorller....

Sayoyo

You can put a helper inside the controller:

class FooController < ApplicationController

  helper do
    def erase_harddisk
      "ouch!"
    end
  end

end

[inside foo.rhtml]

<%= erase_harddisk %>

However, it is strongly discouraged to put application logic
inside your view.

regards
Peter

···

--- Ursprüngliche Nachricht ---
Von: sayoyo@yahoo.com
An: ruby-talk@ruby-lang.org (ruby-talk ML)
Betreff: Re: Can a action view invoke a methode of a controller then
display its results
Datum: Wed, 9 Nov 2005 02:47:11 +0900

Hi,

I have tried the @controller.actionTwo, but it doesn't work. I got the
following msg error:

You have a nil object when you didn't expect it!
The error occured while evaluating nil.actionTwo

I think, it doesn't recognize the contorller....

Sayoyo