当我尝试加载时,以下代码不断抛出NoMethodError。在我重置数据库之前,它一直在工作:
<% pstate= Place.where(statename: @agency.state) %>
<% fips_place = pstate.where(placeshort: @agency.city) %>
<%= place = 'PLACE:' + fips_place.first.placefp %>
但是当我运行时它在控制台中可以正常工作:
> pstate = Place.where(statename: "CA")
> fips_place = pstate.where(placeshort: "Los Angeles")
> place = "PLACE: " + fips_place.first.placefp
=> "PLACE: 85292"
controllers / agencies_controller.rb:
def set_agency
@agency = Agency.find(params[:id])
end
型号/agency.rb:
class Agency < ActiveRecord::Base
has_one :place
...
end
model / place.rb:
class Place < ActiveRecord::Base
belongs_to :agency
end
我要出去肢体和猜想,有在地方表,其没有行statename
和placeshort
匹配@agency.state
和@agency.city
。
因此,然后fips_place.first
返回nil,您的调用尝试将placefp
导致错误。
它在控制台中有效,因为您为statename
和使用了不同的值placeshort
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句