【发布时间】:2014-01-22 05:01:28
【问题描述】:
程序(对象)
#<Program id: 1, country: "UK", title: "Bee Movie", subtitle: "Born to bee wild.",
description: "Barry B. Benson, a bee who has just graduated from ...", official_rating: 6.1,
rating: 6.1, ptype: "movie", year: "2007", imdb: "0389790", tmdb: "5559", tvdb: nil, wiki:
"http://en.wikipedia.org/wiki/Bee_Movie", poster: "/QhbOzpYfBOwrRiuTu9otPk919R.jpg", backdrop:
"/eKXTOIqSFrfN8WTTxrzHMBNiUpB.jpg", trailer: "FFGaS6MDknY", popularity: 4.6948, tags: nil,
created_at: "2013-12-29 21:47:45", updated_at: "2013-12-29 21:48:09">
程序(模型)
class Program < ActiveRecord::Base
attr_accessor :subdomain
def subdomain
'something elaborated'
end
end
Routes.rb
scope ":subdomain" do
resources :programs
end
现在,如果我这样称呼它
p = Program.first
program_path(p)
我明白了
ActionController::UrlGenerationError: No route matches {:locale=>:en, :action=>"show", :controller=>"programs", :id=>nil, :format=>nil} missing required keys: [:subdomain, :id]
我在我的模型中设置了 attr_accessor。还缺少什么?
我的网址应该是:http://example.com/uk/programs/1-bee-movie
顺便说一句,我之所以叫 ':subdomain' 是因为旧的原因。因为之前是 uk.example.com,但现在,对于 seo,应该是 example.com/uk
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-4