ruby on rails 4 - In Rails4 How to assign variables in one controller action and use the value of it in another controller action -
using ruby on rails 4, have ui user can select video file directory path on server. click button runs media info on file , displays xml video along parsing info values xml , assigning value @variables , displaying in ui html page. done in action/method 'evaluate media'. when page loads determines if file has been saved or not , allows user save filename, path, , media info attributes table in mysql. when click save button calls acton/method 'save_file'. when seek assign these variable values model class fields insert table (within controller). values not read. inserts nulls. how can have these variable values assigned in 'evaluate_media' action available 'save_file' action or other action within same controller? based on how setup , defined, thought availble within scope of model/controller object 'file_alias_tfile'.
in 'save_file' action here 3 different ways tried assign value:
full_path = params[:filepath2] <--this 1 puts null table src_location = @radio_button_value <--this 1 puts null table directory = "#{@dir_path_choice}" <--this 1 doesn't called insert script , nil inthe column on insert. (i don't errors , record geet inserted other values.)into table
here save_file action/method code trying assign variable values model fields:
def save_file src_location = @radio_button_value directory = "#{@dir_path_choice}" full_path = params[:filepath2] # "#{@filepathname}" full_filename = "#{@filepath}" alias_code = "#{@file_alias}" validate_status = "#{@file_status}" error_msg = "#{@file_msg}" video_alias_match = "#{@msg_dtl1}" audio_alias_match = "#{@msg_dtl2}" video_format = "#{@video_format}" video_bitrate = "#{@video_bitrate}" video_width = "#{@video_width}" video_height = "#{@video_height}" video_framerate = "#{@video_framerate}" video_aspect_ratio = "#{@video_aspectratio}" video_scan_type = "#{@video_scantype}" video_scan_order = "#{@video_scanorder}" @file_alias_tfile = filealiastfile.new( :src_location => src_location, :directory => directory, :full_path => full_path, :full_filename => full_filename, :file_ext => '', :assigned_status => 'unassigned', :file_status => 'saved', :alias_code => alias_code, :validate_status => validate_status, :error_msg => error_msg, :video_alias_match => video_alias_match, :audio_alias_match => audio_alias_match, :video_format => video_format, :video_bitrate => video_bitrate, :video_width => video_width, :video_height => video_height, :video_framerate => video_framerate, :video_aspect_ratio => video_aspect_ratio, :video_scan_type => video_scan_type, :video_scan_order => video_scan_order, :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')
@file_alias_tfile = filealiastfile.create(file_alias_tfile_params) if @file_alias_tfile.save redirect_to mainpages_home_path, :notice => "the file alias validation has been saved." else redirect_to alias_mainpages_home_path, :notice => "the file alias validation has been saved."
# render = "index" end end
here 'evaluate_media' method values called above in save_file defined:
def evaluate_media @state = 'post' @radio_button_value = params[:location]
#determine if file chosen has been saved database yet. @stored_file = filealiastfile.where(:full_path => params[:filepath2], :deleted_b => 0).first if @stored_file.present? @file_exists_flag = 'y' @file_exists_msg = 'this file , alias has been saved in application.' else @file_exists_flag = 'n' @file_exists_msg = 'this file , alias has not been saved in application yet.' end root_dir = '/watchfolder/miniprod/hot/' provider_dir = "" #store selected value re-display on post. @selected_filepath = params[:filepath2]
filepath = file.join(root_dir, provider_dir, params[:filepath]) @filepath = file.join(params[:filepath2]) @media_xml = ::mediainfo.call(@filepath) #filepath sent in index html @alias_xml = ::aliasgenerator.call(@media_xml) @media_xml_for = "" @alias_xml_for = "" rexml::document.new(@media_xml).write(@media_xml_for, 1) rexml::document.new(@alias_xml).write(@alias_xml_for, 1) alias_parse_doc = "" media_parse_doc = "" alias_parse_doc = rexml::document.new(@alias_xml) media_parse_doc = rexml::document.new(@media_xml) #parse alias xml doc # @aliasgen_ver = alias_parse_doc.elements.each("/aliasgenerator vr=/text()") { |e| e } @aliasgen_ver = rexml::xpath.each(alias_parse_doc, "/aliasgenerator vr=/text()") { |element| element } @file_alias = rexml::xpath.each(alias_parse_doc, "*//alias/text()") { |element| element } @file_status = rexml::xpath.each(alias_parse_doc, "*//error/text()") { |element| element } @file_msg = rexml::xpath.each(alias_parse_doc, "*//error_m/text()") { |element| element } @msg_dtl1 = rexml::xpath.each(alias_parse_doc, "*//closestvideoalias/text()") { |element| element } @msg_dtl2 = rexml::xpath.each(alias_parse_doc, "*//closestaudioalias/text()") { |element| element } #parse video media info xml doc @filepathname = rexml::xpath.each(media_parse_doc, "*//complete_name/text()") { |element| element } @video_format = rexml::xpath.each(media_parse_doc, "//track[@type='video']/format/text()") { |element| element } @video_bitrate = rexml::xpath.each(media_parse_doc, "//track[@type='video']/bit_rate/text()") { |element| element } @video_width = rexml::xpath.each(media_parse_doc, "//track[@type='video']/width/text()") { |element| element } @video_height = rexml::xpath.each(media_parse_doc, "//track[@type='video']/height/text()") { |element| element } @video_aspectratio = rexml::xpath.each(media_parse_doc, "//track[@type='video']/display_aspect_ratio/text()") { |element| element } @video_framerate = rexml::xpath.each(media_parse_doc, "//track[@type='video']/frame_rate/text()") { |element| element } @video_scantype = rexml::xpath.each(media_parse_doc, "//track[@type='video']/scan_type/text()") { |element| element } @video_scanorder = rexml::xpath.each(media_parse_doc, "//track[@type='video']/scan_order/text()") { |element| element } #parse sound media info xml doc # @audio_track = rexml::xpath.each(media_parse_doc, "//track[@type= 'audio']/track/text()") { |element| element } # @track_array = rexml::xpath.each(media_parse_doc,(@audio_track)) {|track| track.elements["bit_rate"].text } # @bitrate = track.elements["bit_rate"].text # end #@audio_tracknum = rexml::xpath.each(media_parse_doc, "//track[@type='audio']/track streamid=/text()") { |element| element } # @audio_format = rexml::xpath.each(media_parse_doc, "//track[@type='audio']/format/text()") { |element| element } # @audio_bitrate = rexml::xpath.each(media_parse_doc, "//track[@type='audio']/bit_rate/text()") { |element| element } # @audio_numchan = rexml::xpath.each(media_parse_doc, "//track[@type='audio']/width/text()") { |element| element } # @audio_language = rexml::xpath.each(media_parse_doc, "//track[@type='audio']/display_aspect_ratio/text()") { |element| element } render :action => :index
end
can please provide me illustration of how can either setup variables correctly pass across actions and/or how assign them in insert database?
your help appreciated!
i found reply in question search still leaves open question.
here link other question , reply more details: same instance variable actions of controller
basically gave me 2 approaches. if 1 action not rendering other, , both methods need access values, need define method assign variables , have both save_file , evaluate_media methods phone call newly define method can access variables. here illustration question addressed index , show methods sharing same variable.
def index set_up_instance_variable end def show set_up_instance_variable end private def set_up_instance_variable @some_instance_variable = foo end
the other solution using before_filter:
you can define instance variables multiple actions using before filter, e.g.:
class foocontroller < applicationcontroller before_filter :common_content, :only => [:index, :show] def common_content @some_instance_variable = :foo end end
now @some_instance_variable accessible templates (including partials) rendered index or show actions.
variables ruby-on-rails-4 model-view-controller methods session-variables
No comments:
Post a Comment