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/
Kevin Olbrich
2006-Jan-04 01:30 UTC
[Rails] Re: recongizing the current controller in views
try using... controller.controller_name and controller.action_name -- Posted via http://www.ruby-forum.com/.
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!
Kevin Olbrich
2006-Jan-04 17:58 UTC
[Rails] Re: Re: recongizing the current controller in views
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'' -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jan-05 14:10 UTC
[Rails] Re: Re: recongizing the current controller in views
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. -- Posted via http://www.ruby-forum.com/.
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:> 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.-- "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!
Alex Young
2006-Jan-05 14:24 UTC
[Rails] Re: Re: recongizing the current controller in views
I think @controller.class.controller_path should work. I''m using that in a layout at the moment. -- Alex Gerard wrote:> 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: > >>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. > >
Kevin Olbrich
2006-Jan-05 17:19 UTC
[Rails] Re: Re: Re: recongizing the current controller in views
Alex Young wrote:> I think @controller.class.controller_path should work. I''m using that > in a layout at the moment. > > -- > Alexif 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. -- Posted via http://www.ruby-forum.com/.