Check if controller action?

Hi Chaps,

How can I check if the page is using a controllers action. for example i
got a helper method that needs to know if a certain controller action is
run on the page or not so as to display different content for it.

Thought it was just

code = “xyz” if Controllername.action?

Cheers,

Rog

On Feb 18, 1:38 pm, Roger M. [email protected]
wrote:

Cheers,

Rog

Posted viahttp://www.ruby-forum.com/.

If I correctly understood what you need, you may try using:

Controller.action_methods.include?params[:action]
Where params[:action] will contain the slice of the url corresponding
to the action in the last request

Hi Roger,

On Wed, 2009-02-18 at 13:38 +0100, Roger M. wrote:

Hi Chaps,

How can I check if the page is using a controllers action. for example i
got a helper method that needs to know if a certain controller action is
run on the page or not so as to display different content for it.

Thought it was just

code = “xyz” if Controllername.action?

Your views have access to the controller and method that rendered them
via controller.controller_name and controller.action_name

e.g.,
<% if controller.controller_name == ‘posts’ %>
<% if controller.action_name == ‘create’ %>
<%= do whatever %>
<% end %>
<% end %>

HTH,
Bill