有什麼區別?此外,爲什麼這不起作用:Rails:attr_accessor和attr_accessible的區別
變量,如base_path沒有被設置。
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()
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @cvit }
end
end
在我看來,我引用@ cvit.some_attribute.html_safe但該屬性爲空,所以我得到一個錯誤。有任何想法嗎?