Belirli bir denetleyiciye gitmek için belirli bir kısıtlamayı karşılayan tüm isteklere sahip olmak istiyorum. Bu yüzden tüm rotaya ihtiyacım var. Bunu Rails'de nasıl belirleyebilirim? Böyle bir şey mi?Ruby on Rails'de bir tüm rota nasıl oluşturulur?
match '*', to: 'subdomain_controller#show', constraints: {subdomain: /.+\.users/}
Bu, tüm olası rotaları gerçekten yakalayacak mı? İç içe pek çok dizin bulunsa bile hiçbirinin kaymaması önemlidir.
Ruby on Rails 3.2'yi kullanma, ancak 4.0'a yükseltmeye hazır.
GÜNCELLEME: '*path'
çalışıyor gibi görünüyor. Bununla birlikte, karşılaştığım sorun, dosya benim public
dizininde bulunduğunda, Rails bunun yerine bunu oluşturuyor.
GÜNCELLEME:
#RAILS 3
#make this your last route.
match '*unmatched_route', :to => 'application#raise_not_found!'
#RAILS 4, needs a different syntax in the routes.rb. It does not accept Match anymore.
#make this your last route.
get '*unmatched_route', :to => 'application#raise_not_found!'
Ve
class ApplicationController < ActionController::Base
...
#called by last route matching unmatched routes.
#Raises RoutingError which will be rescued from in the same way as other exceptions.
def raise_not_found!
raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}")
end
...
end
Bu sorumun yanıtı burada olduğunu düşünüyorum: [http://stackoverflow.com/questions/4132039/rails-redirect-all-unknown-routes-to-root-url][1] [1]: http://stackoverflow.com/questions/4132039/rails-redirect-all-unknown-routes-to-root-url – ksu
@ksu - bu '* path' yani? Ve sonra '' params [: yol] 'yolunu tutar? –