请问一下,下面列出的 'send()' 方法是用来做什么的?当我阅读这段代码时,它看起来毫无意义。
这是一个使用 Ruby 1.8.7 和 Rails 1.2.3 的 Rails 应用程序。请不要向我谈论升级,因为这是客户的环境,所以我没有那样的闲暇。
不用说,我指的语句类似于这样;
def do_schedule
@performance = Performance.new(params[:performance])
@performer = Performer.find(params[:performer_id])
selected_track = params[:selected_track]
if FileTest.exists?(File.expand_path(@performer.photo))
@performance.photo = File.open(File.expand_path(@performer.photo))
end
@performance.audio = File.open(File.expand_path(@performer.send(selected_track)))
if @performance.save
flash[:notice] = 'Performer scheduled.'
redirect_to :controller => :performer, :action => :index
else
render :action => 'schedule'
end
end
表演者模型
class Performer < ActiveRecord::Base
file_column :audio_one
file_column :audio_two
file_column :audio_three
file_column :photo
belongs_to :festival
validates_presence_of :name, :first_name, :last_name, :address, :city, :state, :zip, :daytime_phone, :availability, :stages
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_confirmation_of :email
validates_presence_of :audio_one, :audio_two, :audio_three, :photo, :if => :submitted
after_create :salt_access_key
serialize :availability
serialize :stages
attr_accessor :other_type_of_music
before_save :set_other_type
def set_other_type
if type_of_music == 'Other'
self.type_of_music = "Other - #{other_type_of_music}" unless other_type_of_music.blank?
end
end
def salt_access_key
update_attribute(:access_key, Digest::SHA1.hexdigest("--#{self.id}--#{self.name}--#{self.festival.year}"))
end
def preferred_stages
stages = []
festival = Festival.find(self.festival_id.to_i)
self.stages.collect { | key, value |
id = key.gsub(/[\D]/, '').to_i
if id > 0
stages << festival.performance_stages.find(id).name
end
}
return stages
end
end
这个控制器包含它是性能。我一直在搜索谷歌,试图弄清楚“@performer.send(selected_track)”的实际用途,但感觉自己像在旋涡中划船。
selected_track
变量是什么。您可以记录并向我们显示它,我们可能能够为您提供更多信息。 - Chris Cherryfile_columns
,例如:audio_one
,它被视为文件名,然后传递到File.read
中,文件数据本身被分配给@performance.audio
。 - Chris Cherrydo_schedule
操作的人都可以调用Performer
上的任何方法?对我来说似乎是个坏主意... - Ajedi32