Forum: Ruby on Rails check if controller action??

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.
Roger M. (Guest)
on 2009-02-18 14:38
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
Xuan (Guest)
on 2009-02-18 16:56
(Received via mailing list)
On Feb 18, 1:38 pm, Roger M. <removed_email_address@domain.invalid>
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
bill walton (Guest)
on 2009-02-18 18:02
(Received via mailing list)
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
This topic is locked and can not be replied to.