क्या कोई मुझे समझने में मदद कर सकता है कि नीचे सूचीबद्ध 'भेजें()' विधि का उपयोग किस प्रकार किया जाता है? नीचे दिया गया कोड, जब मैं इसे पढ़ रहा हूं, तो इसका कोई मतलब नहीं है कि यह किस उद्देश्य से सेवा कर रहा है।रेल 100% नया मुद्दा - भेजें() विधि
यह रेल 1.2.3 के साथ रूबी 1.8.7 का उपयोग कर एक रेल ऐप है। कृपया उन्नयन के बारे में मुझे परेशान न करें, यह एक ग्राहक का पर्यावरण है, इसलिए मेरे पास उस तरह का अवकाश नहीं है।
हालांकि कहने की जरूरत नहीं है, मैं जिस बयान का जिक्र कर रहा हूं वह इस तरह है;
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
नियंत्रक है कि इस में निहित है प्रदर्शन है। मैं Google को यह समझने की कोशिश कर रहा हूं कि 'performer.send (select_track) वास्तव में क्या कर रहा है, लेकिन ऐसा लगता है कि मैं एक भंवर के खिलाफ रो रहा हूं।
क्या कोई मुझे इस से बेहतर समझने में मदद कर सकता है?
धन्यवाद।
धन्यवाद ctcherry! महान उदाहरण! आपके द्वारा अभी किए गए method_missing संदर्भ के लिए। नहीं, वास्तव में कलाकार वर्ग में केवल 4 तरीके हैं। 3 (इंडेक्स, शो, और नष्ट) और एक निजी lookup_festival। क्या इसका मतलब यह है कि प्रेषण ठीक से काम करने में असमर्थ है? – Skittles
भेजें अभी भी काम करेगा। यह ट्रिगरिंग क्या करता है इस पर निर्भर करता है कि 'select_track' चर क्या है जिसमें इसे पारित किया जा रहा है। आप इसे लॉग कर सकते हैं और इसे हमें दिखा सकते हैं और हम आपको अधिक जानकारी दे सकते हैं। – ctcherry
इसके अलावा, क्या आप कलाकार मॉडल या नियंत्रक में देख रहे हैं? आप इस प्रेषण कॉल मुद्दे के लिए मॉडल कोड देखना चाहते हैं। – ctcherry