变量变为空

发布于 2024-11-28 13:18:13 字数 6216 浏览 5 评论 0原文

我有一个变量不知何故变成空!注意控制器中的调试器。 编辑:看起来控制器和视图中的 cvit 对象不一样。我该如何解决这个问题?

在视图中:

<%= content_tag(:img,
      content_tag(:map, @cvit.overlay_coords_gray.html_safe, :name => "#CViT_image_gray"),
        {:src => "/data/04_cvit/#{@cvit.cvt_file}_gray.png", :usemap =>"#CViT_image_gray", :style => "display:block;margin-left:auto;margin-right:auto"} )
%>

我收到此错误:

undefined method `html_safe' for nil:NilClass

它引用@cvit.overlay_coords_gray

这是基本模型和控制器:

模型:

class Cvit < ActiveRecord::Base
  attr_accessible :species,:program,:textup,:e_value,:filter,:min_identity,:cluster_dist,:fileup_file_name
  attr_accessor :base_path, :fa_file, :text_file, :dbase, :source, :bl_file, :bl_sorted, :gff_file, :cvt_file, :db, :overlay_coords_gray

  def initilize(*args)
     super(*args)
  end

  def cvitSetup()
    self.base_path = "blast_cvit/"
    self.fa_file = "input.fa"
    .
    .
  end
end

控制器:

def show
    @cvit = Cvit.find(params[:id])
    @cvit.cvitSetup()
    @cvit.blast()
    @cvit.generateGff()
    @cvit.generateCvitImage()

    logger.debug "overlay coords: #{@cvit.overlay_coords_gray.inspect}"


    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @cvit }
    end
  end

日志信息(注意使用调试器显示其不为空!!!)

Creating scope :page. Overwriting existing method Cvit.page.
  SQL (0.5ms)  SHOW TABLES
  Cvit Load (0.3ms)  SELECT `cvits`.* FROM `cvits` WHERE `cvits`.`id` = 5 LIMIT 1


Started GET "/cvits/5" for 129.186.136.212 at Fri Aug 05 11:19:50 -0500 2011
  Processing by CvitsController#show as HTML
  Parameters: {"id"=>"5"}
Creating scope :page. Overwriting existing method Cvit.page.
      !!!DEBUGGER!!! overlay coords: "<area onmouseover=\"mouseover_toggle('Glyma02g37330..173..179..694..700')\" shape=\"rect\" coords=\"173,694,179,700\" href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=42605601;stop=42707190;ref=Gm02;h_feat=Glyma02g37330@yellow\" target=\"_blank\"></area>\n<div id=\"Glyma02g37330..173..179..694..700\" style=\"border: 2px solid rgb(0, 0, 0);background-color: rgb(239,237,233); z-index: 1; visibility: hidden; position: absolute; width: 250px; left: 394px; top: 774px;\"><input type=\"button\" name=\"closeDiv\" value=\"Close\" onclick=\"mouseover_toggle('Glyma02g37330..173..179..694..700')\"></input><br /> Query = Glyma02g37330 <br />Target = Glyma02g37330 <br />Chromosome = Gm02 <br />Start = 42605601 <br />End = 42707190  <br /><a href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=42605601;stop=42707190;ref=Gm02;h_feat=Glyma02g37330@yellow\">Click to view in GBrowse</a></div>\n<area onmouseover=\"mouseover_toggle('Glyma02g37330..1013..1019..723..729')\" shape=\"rect\" coords=\"1013,723,1019,729\" href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=44520215;stop=44621936;ref=Gm14;h_feat=Glyma14g35580@yellow\" target=\"_blank\"></area>\n<div id=\"Glyma02g37330..1013..1019..723..729\" style=\"border: 2px solid rgb(0, 0, 0);background-color: rgb(239,237,233); z-index: 1; visibility: hidden; position: absolute; width: 250px; left: 394px; top: 774px;\"><input type=\"button\" name=\"closeDiv\" value=\"Close\" onclick=\"mouseover_toggle('Glyma02g37330..1013..1019..723..729')\"></input><br /> Query = Glyma02g37330 <br />Target = Glyma14g35580 <br />Chromosome = Gm14 <br />Start = 44520215 <br />End = 44621936  <br /><a href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=44520215;stop=44621936;ref=Gm14;h_feat=Glyma14g35580@yellow\">Click to view in GBrowse</a></div>\n<area onmouseover=\"mouseover_toggle('Glyma02g37330..313..319..147..153')\" shape=\"rect\" coords=\"313,147,319,153\" href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=6118288;stop=6218620;ref=Gm04;h_feat=Glyma04g07910@yellow\" target=\"_blank\"></area>\n<div id=\"Glyma02g37330..313..319..147..153\" style=\"border: 2px solid rgb(0, 0, 0);background-color: rgb(239,237,233); z-index: 1; visibility: hidden; position: absolute; width: 250px; left: 394px; top: 774px;\"><input type=\"button\" name=\"closeDiv\" value=\"Close\" onclick=\"mouseover_toggle('Glyma02g37330..313..319..147..153')\"></input><br /> Query = Glyma02g37330 <br />Target = Glyma04g07910 <br />Chromosome = Gm04 <br />Start = 6118288 <br />End = 6218620  <br /><a href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=6118288;stop=6218620;ref=Gm04;h_feat=Glyma04g07910@yellow\">Click to view in GBrowse</a></div>\n"
  CACHE (0.0ms)  SELECT `cvits`.* FROM `cvits` WHERE `cvits`.`id` = 5 LIMIT 1
Rendered cvits/show.html.erb within layouts/glycine_max (3.3ms)
Completed 500 Internal Server Error in 4942ms

ActionView::Template::Error (undefined method `html_safe' for nil:NilClass):


    88:         <a href="/data/02_blastout/<%= @cvit.bl_file %>"><%= bl_state %></a>, 
    89:     <a href="/data/03_gff/<%= @cvit.gff_file %>">CViT gff file</a>
    90:     <%= content_tag(:img, 
    91:             content_tag(:map, @cvit.overlay_coords_gray.html_safe, :name => "#CViT_image_gray"), 
    92:         {:src => "/data/04_cvit/#{@cvit.cvt_file}_gray.png", :usemap =>"#CViT_image_gray", :style => "display:block;margin-left:auto;margin-right:auto"} ) 
    93:             
    94:     %>
  app/views/cvits/show.html.erb:91:in `_app_views_cvits_show_html_erb___1813186540_17224422620_0'
  app/controllers/cvits_controller.rb:38:in `show'

Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (8.8ms)
Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (16.5ms)

I have a variable that becomes null somehow! Note the debugger in the controller.
EDIT: looks like the cvit object is not the same in the controller and the view. How do I fix this problem?

in the view:

<%= content_tag(:img,
      content_tag(:map, @cvit.overlay_coords_gray.html_safe, :name => "#CViT_image_gray"),
        {:src => "/data/04_cvit/#{@cvit.cvt_file}_gray.png", :usemap =>"#CViT_image_gray", :style => "display:block;margin-left:auto;margin-right:auto"} )
%>

I get this error:

undefined method `html_safe' for nil:NilClass

which refers to @cvit.overlay_coords_gray

Here is basic model and controller:

model:

class Cvit < ActiveRecord::Base
  attr_accessible :species,:program,:textup,:e_value,:filter,:min_identity,:cluster_dist,:fileup_file_name
  attr_accessor :base_path, :fa_file, :text_file, :dbase, :source, :bl_file, :bl_sorted, :gff_file, :cvt_file, :db, :overlay_coords_gray

  def initilize(*args)
     super(*args)
  end

  def cvitSetup()
    self.base_path = "blast_cvit/"
    self.fa_file = "input.fa"
    .
    .
  end
end

controller:

def show
    @cvit = Cvit.find(params[:id])
    @cvit.cvitSetup()
    @cvit.blast()
    @cvit.generateGff()
    @cvit.generateCvitImage()

    logger.debug "overlay coords: #{@cvit.overlay_coords_gray.inspect}"


    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @cvit }
    end
  end

Log information (notice use of debugger showing its not null!!!!)

Creating scope :page. Overwriting existing method Cvit.page.
  SQL (0.5ms)  SHOW TABLES
  Cvit Load (0.3ms)  SELECT `cvits`.* FROM `cvits` WHERE `cvits`.`id` = 5 LIMIT 1


Started GET "/cvits/5" for 129.186.136.212 at Fri Aug 05 11:19:50 -0500 2011
  Processing by CvitsController#show as HTML
  Parameters: {"id"=>"5"}
Creating scope :page. Overwriting existing method Cvit.page.
      !!!DEBUGGER!!! overlay coords: "<area onmouseover=\"mouseover_toggle('Glyma02g37330..173..179..694..700')\" shape=\"rect\" coords=\"173,694,179,700\" href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=42605601;stop=42707190;ref=Gm02;h_feat=Glyma02g37330@yellow\" target=\"_blank\"></area>\n<div id=\"Glyma02g37330..173..179..694..700\" style=\"border: 2px solid rgb(0, 0, 0);background-color: rgb(239,237,233); z-index: 1; visibility: hidden; position: absolute; width: 250px; left: 394px; top: 774px;\"><input type=\"button\" name=\"closeDiv\" value=\"Close\" onclick=\"mouseover_toggle('Glyma02g37330..173..179..694..700')\"></input><br /> Query = Glyma02g37330 <br />Target = Glyma02g37330 <br />Chromosome = Gm02 <br />Start = 42605601 <br />End = 42707190  <br /><a href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=42605601;stop=42707190;ref=Gm02;h_feat=Glyma02g37330@yellow\">Click to view in GBrowse</a></div>\n<area onmouseover=\"mouseover_toggle('Glyma02g37330..1013..1019..723..729')\" shape=\"rect\" coords=\"1013,723,1019,729\" href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=44520215;stop=44621936;ref=Gm14;h_feat=Glyma14g35580@yellow\" target=\"_blank\"></area>\n<div id=\"Glyma02g37330..1013..1019..723..729\" style=\"border: 2px solid rgb(0, 0, 0);background-color: rgb(239,237,233); z-index: 1; visibility: hidden; position: absolute; width: 250px; left: 394px; top: 774px;\"><input type=\"button\" name=\"closeDiv\" value=\"Close\" onclick=\"mouseover_toggle('Glyma02g37330..1013..1019..723..729')\"></input><br /> Query = Glyma02g37330 <br />Target = Glyma14g35580 <br />Chromosome = Gm14 <br />Start = 44520215 <br />End = 44621936  <br /><a href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=44520215;stop=44621936;ref=Gm14;h_feat=Glyma14g35580@yellow\">Click to view in GBrowse</a></div>\n<area onmouseover=\"mouseover_toggle('Glyma02g37330..313..319..147..153')\" shape=\"rect\" coords=\"313,147,319,153\" href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=6118288;stop=6218620;ref=Gm04;h_feat=Glyma04g07910@yellow\" target=\"_blank\"></area>\n<div id=\"Glyma02g37330..313..319..147..153\" style=\"border: 2px solid rgb(0, 0, 0);background-color: rgb(239,237,233); z-index: 1; visibility: hidden; position: absolute; width: 250px; left: 394px; top: 774px;\"><input type=\"button\" name=\"closeDiv\" value=\"Close\" onclick=\"mouseover_toggle('Glyma02g37330..313..319..147..153')\"></input><br /> Query = Glyma02g37330 <br />Target = Glyma04g07910 <br />Chromosome = Gm04 <br />Start = 6118288 <br />End = 6218620  <br /><a href=\"http://soybase.org/gb2/gbrowse/gmax1.01/?start=6118288;stop=6218620;ref=Gm04;h_feat=Glyma04g07910@yellow\">Click to view in GBrowse</a></div>\n"
  CACHE (0.0ms)  SELECT `cvits`.* FROM `cvits` WHERE `cvits`.`id` = 5 LIMIT 1
Rendered cvits/show.html.erb within layouts/glycine_max (3.3ms)
Completed 500 Internal Server Error in 4942ms

ActionView::Template::Error (undefined method `html_safe' for nil:NilClass):


    88:         <a href="/data/02_blastout/<%= @cvit.bl_file %>"><%= bl_state %></a>, 
    89:     <a href="/data/03_gff/<%= @cvit.gff_file %>">CViT gff file</a>
    90:     <%= content_tag(:img, 
    91:             content_tag(:map, @cvit.overlay_coords_gray.html_safe, :name => "#CViT_image_gray"), 
    92:         {:src => "/data/04_cvit/#{@cvit.cvt_file}_gray.png", :usemap =>"#CViT_image_gray", :style => "display:block;margin-left:auto;margin-right:auto"} ) 
    93:             
    94:     %>
  app/views/cvits/show.html.erb:91:in `_app_views_cvits_show_html_erb___1813186540_17224422620_0'
  app/controllers/cvits_controller.rb:38:in `show'

Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (8.8ms)
Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (16.5ms)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2024-12-05 13:18:13

您在视图中的某处启用了片段缓存:

CACHE (0.0ms)  SELECT `cvits`.* FROM `cvits` WHERE `cvits`.`id` = 10 LIMIT 1

您得到了错误的对象:您要求“5”,并看到上面的查询是 10。

禁用缓存并重试,无论如何,该缓存都应该被修复。

You have fragment caching enabled somewhere in the view:

CACHE (0.0ms)  SELECT `cvits`.* FROM `cvits` WHERE `cvits`.`id` = 10 LIMIT 1

You are getting the wrong object: you asked for '5' and see the query above does 10.

Disable cache and try again, in any case this cache should be fixed.

撑一把青伞 2024-12-05 13:18:13

尝试在渲染之前在控制器中执行 @dummy = @cvit.clone 或 @dummy = @cvit.dup ;然后在视图中使用@dummy 而不是@cvit。另外,完成此操作后,检查控制器本身是否将 attr_accessors 的值复制到@dummy。如果它们被复制,则检查视图并查看 attr_accessors 现在是否为非零? – 扎巴 2011 年 8 月 5 日 21:37
哇谢谢你扎巴!!!!!!!尽管克隆和复制具有不同的 object_id,但它们并没有消除 attr_accessor 变量!谢谢谢谢谢谢!!!!!!!!!!!! – 本杰明 2011 年 8 月 5 日 21:49

Try doing @dummy = @cvit.clone or @dummy = @cvit.dup in the controller, before the render; and then using @dummy instead of @cvit in the view. Also, after doing that, check in controller itself if the values for the attr_accessors got copied over to @dummy. If they got copied, then check in view and see if the attr_accessors are non-nil now? – Zabba Aug 5 '11 at 21:37
WOW THANK you Zabba!!!!!! Although the clones and dups had different object_ids they did NOT nil out the attr_accessor variables!!! THANK YOU THANK YOU!!!!!!!!!!!! – Benjamin Aug 5 '11 at 21:49

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文