Need Help passing an instance variable to another method for insert in ruby on rails 4 -



Need Help passing an instance variable to another method for insert in ruby on rails 4 -

i new ror , spent of day trying work. have tried using before_filter , cannot object insert in method.

the view index, file selected in view , button validate file clicked calls method 'evaluate_media' in method, values based on file path , name selected , can insert record values in method. problem don't want automatic save. when 'evaluate_media' method done displays either save button or update button based on if file submitted exists in database. user can take save/update record or now. button calls 'save_file' action. problem info save in 'evaluate_media' action file not accessible save_file or update_file actions. believe session variables might reply not find examples setup correctly , working in application. can please tell me , show me proper code pass value 'evaluate_media' action save_file or update_file actions?

here code assign values new record in evaluaate_media method:

if @file_exists_flag == 'new' # assign parameter values new save @file_alias_tfile = filealiastfile.new( {:src_location => @radio_button_value, :directory => @dir_path_choice, :full_path => @selected_filepath, :full_filename => @filepath, :file_ext => '', :assigned_status => 'unassigned', :file_status => 'saved', :alias_code => @file_alias.to_s, :validate_status => @file_status.to_s, :error_msg => @file_msg.to_s, :video_alias_match => @msg_dtl1.to_s, :audio_alias_match => @msg_dtl2.to_s, :video_format => @video_format.to_s, :video_bitrate => @video_bitrate.to_s, :video_width => @video_width.to_s, :video_height => @video_height.to_s, :video_framerate => @video_framerate.to_s, :video_aspect_ratio => @video_aspectratio.to_s, :video_scan_type => @video_scantype.to_s, :video_scan_order => @video_scanorder.to_s, :video_alias_code => '', :audio_alias_code => '', :bus_prod_initiative_id => 0, :status => 'active', :start_date => datetime.now.to_date, :end_date => '', :deleted_b => 0, :created_by => 'admin', :updated_by => 'admin'} ) end

then if user clicks save, save_file method called , here code save values evaluate_media database:

def save_file @file_alias_tfile = filealiastfile.create(@file_alias_tfile) @file_alias_tfile.save end

i figure update same save included 1 case here. help appreciated. give thanks you!

first of all,

def save_file @file_alias_tfile = filealiastfile.create(@file_alias_tfile) @file_alias_tfile.save end

modelname.create() equivalent modelname.new(....).save. sec line should deleted.

you could this:

if @file_exists_flag == 'new' session[:my_file] = filealiastfile.new( .... ) def save_file session[:my_file].save end

however, it's not recommended save model objects in session. instead, should save object in database; save id of object in session. know, "but don't want save object in database until user confirms". have ever heard of destroy() method? instance,

filealias.destroy(session[:file_id])

which deletes record in file_aliases table id equal session[:file_id].

when 'evaluate_media' method done displays either save button or update button based on if file submitted exists in database.

so, create() record (remember saves record), , if user clicks save button, nothing. if user clicks update button, delete record database , delete id session. example:

if @file_exists_flag == 'new' my_file = filealias.create( .... ) session[:file_id] = my_file.id def save_file #render page end def update_file my_file = filealias.destroy(session[:id]) session.delete[:file_id] #do my_file? end

variables ruby-on-rails-4 model-view-controller session-variables

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -