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

  • fast2hell

    fast2hell

    16 AĞUSTOS 2006
  • PamtheBlamofficial

    PamtheBlamof

    31 Aralık 2010
  • The Slow Mo Guys

    The Slow Mo

    15 AĞUSTOS 2010