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

  • AutoHotkey Tutorials

    AutoHotkey T

    29 Mayıs 2010
  • lilstevie89

    lilstevie89

    25 Mart 2011
  • RFS Dan

    RFS Dan

    22 Temmuz 2014