I posted a question on how to share variables across actions in same controller. I found this Q/A that answered my question mostly but still left a pending question raised in this submission. Here is the link for the Q/A I found that might help someone else: Same instance variable for all actions of a controller

Here is the link for my initial question which I answered with the link above: In Rails4 How to assign variables in one controller action and use the value of it in another controller action

Now that I know I can use the before_filter and create a private action that can then be referenced from the various actions in the controller which appears to be great for known constant variables, how do I set it up in my specific case where the values change based on user action and are defined in the user interactive action?

I have a method called 'evaluate_media'. This method allows the user to select a file from various directory paths and then runs media info on the selected video file and parses the xml for certain attributes (like bitrate, aspect_ratio) and assigns the values to variables in the action. Is there any way I can share the looked up and assigned variables in this action with the other actions like the common_components without it being private and just for variable assignment? Can you please show me an example of how to do this? I did try the before_filter as so and it doesn't even call the insert. It just refreshes the page. before_filter :evaluate_media, :only => [:save_file]

Just as a refresher from my first question, After I gather this information in my evaluate_media action, I have a save button that calls the save_file method that will store this information gathered in the evaluate_media action.

Here are the 2 defined methods:

def save_file    

        src_location = @radio_button_value
        directory = "#{@dir_path_choice}"
        full_path = @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')


    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 not been saved."
    end
  end

 def evaluate_media

     @state = 'post'
     @radio_button_value = params[:location]

     @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 and Alias has been saved in application.'
     else
        @file_exists_flag = 'N'
        @file_exists_msg = 'This File and Alias has NOT been saved in application yet.'
      end

          root_dir = '/watchfolder/miniprod/hot/'
          provider_dir = ""

       @selected_filepath = params[:filepath2]
       @filepath = params[:filepath2]

       @media_xml = ::MediaInfo.call(@filepath)  
       @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 = 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 }   

       render :action => :index
   end

Related posts

Recent Viewed