开发者

Variable becomes null

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)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜