Recongizing the current controller in views


#1

alright i am doing a simple self blog in ruby. Now iw ant to be able to
determine which controller action i am in inside _form.rhtml.

So if i am in new or the creation control than i want to insert the text
box
for topics else i want to display the topic base on id. (i could do
those
already, i just need help finding the right if statement…

something like (if currentpage == “blogs/new”) …<input type = text…

I want to be able to do this inside the view.


Express yourself instantly with MSN Messenger! Download today - it’s
FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


#2

try using…

controller.controller_name and
controller.action_name


#3

Kevin O. wrote:

Gerard wrote:

Is there a way to point out the module (or controller group if you will)
I’m
in?

Thanx!

I think controller.controller_path might give you ‘module/controller’

On further investigation it seems that controller.controller_path is not
callable from a view. The method exists in the ActiveController::Base
class, but for some reason I can’t get it to work. My guess is that
there is something in the way rails handles method inheritance that is
preventing it from working in a subclass. If you copy the code from the
base file to your application controller, it may work. At the very
least, you should be able to determine how to return the module name
from the code.

It may also be possible to do this by writing a custom routing rule that
accounts for the module.


#4

Kevin,

Thanx. Over my head for now, but maybe I’ll write a helper that gets me
the
name of the parent dir the controller is in.

Regards,

Gerard.

On Thursday 05 January 2006 15:09, Kevin O. tried to type something
like:

On further investigation it seems that controller.controller_path is not
callable from a view. The method exists in the ActiveController::Base
class, but for some reason I can’t get it to work. My guess is that
there is something in the way rails handles method inheritance that is
preventing it from working in a subclass. If you copy the code from the
base file to your application controller, it may work. At the very
least, you should be able to determine how to return the module name
from the code.

It may also be possible to do this by writing a custom routing rule that
accounts for the module.


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!


#5

I think @controller.class.controller_path should work. I’m using that
in a layout at the moment.


Alex


#6

Alex Y. wrote:

I think @controller.class.controller_path should work. I’m using that
in a layout at the moment.


Alex

if you look closely at the activecontroller::base code you will see that
controller_path is defined as a singleton method (I think). This means
you need to use the controller.class.controller_path to access it.

The other controller functions have normal public methods defined for
them that call an underlying class method. Apparently someone forgot to
write one for controller_path.

since they used the ‘class << self’ idiom to define several methods in
the core, it is not at all obvious from the RDocs that this method
should be treated like a class method, hence the confusion.

Good tip, Alex.


#7

Kevin,

In addition, I’m in my first rails app and already grouping my
controllers
into modules e.g:

app/controllers/crm
app/controllers/crm/customer_controller.rb
app/controllers/crm/mailing_controller.rb

app/controllers/mgmt
app/controllers/mgmt/product_controller.rb
app/controllers/mgmt/vendor_controller.rb

Is there a way to point out the module (or controller group if you will)
I’m
in?

Thanx!

GrtzG

On Wednesday 04 January 2006 02:30, Kevin O. tried to type
something
like:

try using…

controller.controller_name and
controller.action_name


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!


#8

Gerard wrote:

Is there a way to point out the module (or controller group if you will)
I’m
in?

Thanx!

I think controller.controller_path might give you ‘module/controller’