SORU
30 Temmuz 2009, PERŞEMBE


Nasıl Raylar geçerli yol bulabilir miyim?

Raylar bir filtre içinde geçerli rotayı bilmek istiyorum. Onun ne olduğunu nasıl öğrenebilirim?

Kaynaklar, DİNLENME ve yollar adlı yapıyorum.

CEVAP
30 Temmuz 2009, PERŞEMBE


URİ öğrenmek için:

current_uri = request.env['PATH_INFO']
# If you are browsing http://example.com/my/test/path, 
# then above line will yield current_uri as "/my/test/path"

Rota yani denetleyicisi bulmak için, eylem ve kullanımı

path = ActionController::Routing::Routes.recognize_path "/your/path/here/"

# ...or newer Rails versions:
#
path = Rails.application.routes.recognize_path('/your/path/here')

controller = path[:controller]
action = path[:action]
# You will most certainly know that params are available in 'params' hash

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Evan Coury

    Evan Coury

    29 NİSAN 2007
  • RinconDynamic

    RinconDynami

    1 EKİM 2011
  • TWiT Netcast Network

    TWiT Netcast

    27 EKİM 2005