对于在 Rails 中针对城市、地区、国家显示 URL 和处理 View ,您有何建议?
即:
/us/ca/旧金山
/countries/us/regions/ca/cities/San-Fransisco
应该能够: 列出所有国家/地区、列出国家/地区内的所有地区以及列出地区和国家/地区内的所有城市。
您将在哪里放置用于显示一个国家/地区的所有区域的代码?:
/我们/地区/
/我们
代码应该位于区域( Action 显示)还是国家( Action 索引) Controller 中?
最佳答案
同意阿恩的观点。我没有发现第一个变体有任何问题。
对于第二个问题,你最好在RegionsController中获取区域列表。
说你想
GET /us/regions
那么你应该将其路由到
class RegionsController < ApplicationController
# GET /:country_code/regions
# GET /regions
def index
@countries =
if params[:country_code]
Country.find_by_code(params[:country_code]).regions
else
Region.all # get all regions if country_code is not set
end
end
end
关于ruby-on-rails - Rails 中城市/地区/国家的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383734/