Forum: Ruby on Rails recongizing the current controller in views

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.
Ced75c12749ccde0163b5abf91a16418?d=identicon&s=25 chun ping wang (Guest)
on 2006-01-04 02:27
(Received via mailing list)
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/onm00200471a...
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-01-04 02:30
try using...

controller.controller_name  and
controller.action_name
4710a8ada2adc162aaee4288d9879d8e?d=identicon&s=25 Gerard (Guest)
on 2006-01-04 09:11
(Received via mailing list)
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 Olbrich 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!
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-01-04 18:58
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'
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-01-05 15:09
Kevin Olbrich 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.
4710a8ada2adc162aaee4288d9879d8e?d=identicon&s=25 Gerard (Guest)
on 2006-01-05 17:44
(Received via mailing list)
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 Olbrich 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!
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-05 17:44
(Received via mailing list)
I think @controller.class.controller_path should work.  I'm using that
in a layout at the moment.

--
Alex
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-01-05 18:19
Alex Young 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.
This topic is locked and can not be replied to.