ruby on rails 3 - Destroy Record if Dependant record is not found -


I am trying to write a script that checks to see if the related record exists or not. If I do not want to delete the reference record

I'm new to Ruby.

  if Hotload.find (lead.id) .exists? Leadid = Lead.find (lead.id) leadid.destroy end  

Error message:

  ActiveRecord :: RecordNotFound (Could not find the hotel with ID = 148): App / Controller / users_controller.rb: 64: Update in 'Block in Lead' app / controllers / users_controller.rb: 47: `Leeds'  

:

  def load_lead = [] truck_laid = [] hotelload_lades = [] # I have added another route for users: ID / leads and users / leads because I was not sure That it is anywhere else Emal was. @ Lightweight = leads. Where (: user_id = & gt; param [[id]] current_user.id) @ leeds.each | Lead | If lead.post_type == 'load' load_leads.push lead.type_id Elspha Lead. Post_type == 'Truck' truck_lades. Animal Lead. Type ADSL Lead. Post_type == 'HotLoad' hotload_leads.push lead.type_id Hotload.where (: id = & gt; lead.id). Lead_id = lead.edge lead_id.destroy end and sava_load = load.find (load_lades, order = & gt; "# {sort_load_column +" "+ sort_direction}"). Pagenet (: page = & gt; Paramas [: load_lays_page], per-page => 10) @saved_trucks = truck.find (truck_lades, order => "# {sort_truck_column +" "+ sort_direction}" ). Paginated (: page = & gt; params [truck_leads_page], per-page => 10) @saved_hotloads = Hotload.find (hotelload_lades ,: order = & gt; "# {sort_load_column +" "+ sort_direction}" ). Paginated (: page = & gt; parameter [: hotload_leads_page]: Per_page = & gt; 10) end  

error now

  ActiveRecord :: RecordNotFound (Not all hotelals with ID were found (1590, 1479, 1478, 1468, 1476) (4 results were found, but 5 were looking for)): App / Controller / users_controller.rb: 62: In Leeds' Code>   

you should change the code

  if Hotload.find_by ( Id: lead.id) .bl ank? Leadid = lead.id leadid.destroy end  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -