bad value for range

环境: ruby 1.9.3p0, rails 3.2.6

 

RegionDetail 和 Area是1:N的关系,想在页面中输出RegionDetail所对应的所有area列表

 

area:model

class Area < ActiveRecord::Base
  belongs_to :region_detail
  attr_accessible :area_name
end

regiondetail:model

class RegionDetail < ActiveRecord::Base
  has_many :manual_testers
  has_many :areas
  attr_accessible :region_name
end
 

 

发送get请求

<%= link_to "region", :controller => "task_manager", :action => "showarea", :id => 1 %> 

 

控制器接收id,通过id找到对应的RegionDetail,在调用areas,得到area对象数组

  def showarea ##查找所有属于该大区的地区,作为地区页面显示
    @areas = RegionDetail.find(params[:id]).areas
  end

在视图页面,循环输出area对象

<% @areas.each do |area| %>
	<%= link_to area.area_name ,:controller => "task_manager", :action => "showscript", :id => area.id %>
<% end %>

 

发送get请求:task_manager/showarea?id=1后,页面提示错误信息如下:

Started GET "/task_manager/showarea?id=1" for 127.0.0.1 at 2012-08-22 10:56:42 +0800
Processing by TaskManagerController#showarea as HTML
  Parameters: {"id"=>"1"}
  [1m[36mRegionDetail Load (0.0ms)[0m  [1mSELECT "region_details".* FROM "region_details" WHERE "region_details"."id" = ? LIMIT 1[0m  [["id", "1"]]
  Rendered task_manager/showarea.html.erb within layouts/application (187.3ms)
Completed 500 Internal Server Error in 390ms

ActionView::Template::Error (bad value for range):
    1: <% @areas.each do |area| %>
    2: 	<%= link_to area.area_name ,:controller => "task_manager", :action => "showscript", :id => area.id %>
    3: <% end %>
  app/views/task_manager/showarea.html.erb:1:in `_app_views_task_manager_showarea_html_erb__411803582_18633972'

 有的时候还会报这样的错误:

Started GET "/areas" for 127.0.0.1 at 2012-08-22 10:57:10 +0800
Processing by AreasController#index as HTML
  [1m[35mArea Load (0.0ms)[0m  SELECT "areas".* FROM "areas" 
  Rendered areas/index.html.erb within layouts/application (140.5ms)
Completed 500 Internal Server Error in 156ms

ActionView::Template::Error (wrong number of arguments(1 for 0)):
    12: <% @areas.each do |area| %>
 

换用ruby1.8.7版本后,问题就解决了,查找资料后,发现时ruby1.9.3p0的一个bug

你可能感兴趣的:(bad value for range)