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


I'm new to ROR and it has completed most of the day to work. I have tried to use the first_filters and I can not get my object inserted in the second method.

The view index is selected in a file view, and then the button is clicked to validate the file which calls a method called 'evaluate_media' in this method, I look at the values ​​based on the selected name and I can successfully insert records with all the values ​​in this method. The problem is that I do not want to autosave when the 'evaluate_media' method is complete, then it displays the file with the save button or an update button when it is present in the database already present. Users can then save / update records or now. This button calls the 'save_file' verb The problem is that all the information saved in the 'evaluate_media' action for the file is not accessible to the save_file or update_file verbs. I believe the session variable may be my answer but I could not find a good example to set it up correctly and to work in my application. Will someone please tell me and show me the proper code to pass the value for the 'save_file' or 'update_file' actions to save me from 'valueate_media'?

Here is the code where I assign the value to a new record in my evaluaate_media method:

  @file_exists_flag == Assignment parameter value for new 'new' @file_alias_tfile = Save if FileAliasTfile.new ({: src_location = & gt; @radio_button_value ,: directory = & gt; @dir_path_choice,: full_path = & gt; @selected_filepath ,: full_filename = & gt; @filepath, file_ext = & Gt; ',: assigned_status = & gt;' not assigned ',: file_status = & gt;' saved ',: alias_code = & gt; @file_alias.to_s ,: validate_status = & gt; @ file_status.to_s ,: ERROR_MSG = & Gt; @ file_msg.to_s ,: video_alias_match = & gt; @ msg_dtl1.to_s ,: audio_alias_match = & gt; @ msg_dtl2.to_s ,: video_format = & gt; @video_format. To_s,: video_bitrate = & gt; Video_bitrate.to_s ,: video_width = & gt; @ video_width.to_s ,: video_height = & gt; @ video_height.to_s ,: video_framerate = & gt; @ video_framerate.to_s ,: video_asPekt_artio => @Video_Scatcherio.tt_s ​​,: Video_scan_type = & gt; @video_sccip.o_s ,: video_scan_order = & gt; @ Video_scorder.tt_s ​​,:Video_Leassod => '',: Audio_alias_code = & gt; '',: Bus_prod_initiative_id = & gt; 0 ,: position = & gt; 'Active',: start_date = & gt; Date time Nov.at_det ,:and_data & gt; '',: Deleted_b = & gt; 0 ,: created = by => 'Admin' ,: updated_by = & gt; 'Admin'}) Finally   

Then the user clicks on saving, the save_file method is called and the database is code to save values ​​from evaluate_media: < Pre> def save_file @file_alias_tfile = FileAliasTfile.create (@file_alias_tfile) @ end file_alias_tfile.save

I understand the update will be the same as saving so I only include a case here. Thanks for your help is appreciated!

itemprop = "text">

First of all,

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

ModelName.create () ModelName.new (equals ....) .save < / Code>. Then the second line should be removed.

You can do this:

  if @file_exists_flag == 'new' session [: my_file] = files aliasfile.nu (. ...) def save_file session [: my_file]. Save end   

However, this session is generally not recommended to save model objects. Instead, you should save the object to the database; Then save the object's ID in the session. I know, "but I do not want to save the object in the database until the user verifies". Have you ever heard about the destroyed () method? For example,

  FileAlias.destroy (session [: file_id])   

which records the record in the file_aliases table with the equivalent of an ID < Code> session [: file_id] .

When the 'evaluate_media' method is complete, the file is displayed back with the save button or the update button when it already exists in the database.

Then, () make a record (remember that saves records), and if the user clicks the save button, then do nothing. If the user clicks the update button, delete the record from the database and delete the ID from the session. For example:

  if @file_exists_flag == 'new' my_file = FileAlias.create (....) session [: file_id] = my_file.iddef save_file #renderSome page enddef Update_file My_file = FileAlias.destroy (session [: id]) session.delete [: file_id] # with some my_file? End    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -