hi all, I am searching the database to show some clients with the following code: @client = Client.find(params[:id], :conditions => [''user_id = ?'',session[:user_id]]) if the combination is ok - i see the record on my page if not - RoR shoot an error:>> Couldn''t find Client with ID=16 AND (user_id = 5)how can I catch that error? thanks for any tip andreas -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andreas Schneider wrote:> hi all, > > I am searching the database to show some clients with the following > code: > > @client = Client.find(params[:id], > :conditions => [''user_id = ?'',session[:user_id]]) > > > if the combination is ok - i see the record on my page > if not - RoR shoot an error: >>> Couldn''t find Client with ID=16 AND (user_id = 5) > > how can I catch that error? > > thanks for any tip > andreasgot it: @client = Client.find(:first, :conditions => [''id = ? and user_id = ?'', params[:id], session[:user_id]]) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
if u want to catch an error, use "rescue" usually in a method/action inside a controller u add like these (if you want to catch/raise errors on record not found) def your_method your_code... rescue ActiveRecord:RecordNotFound insert_your_code_here end Andreas Schneider wrote:> Andreas Schneider wrote: >> hi all, >> >> I am searching the database to show some clients with the following >> code: >> >> @client = Client.find(params[:id], >> :conditions => [''user_id = ?'',session[:user_id]]) >> >> >> if the combination is ok - i see the record on my page >> if not - RoR shoot an error: >>>> Couldn''t find Client with ID=16 AND (user_id = 5) >> >> how can I catch that error? >> >> thanks for any tip >> andreas > > got it: > @client = Client.find(:first, :conditions => [''id = ? and user_id = > ?'', params[:id], session[:user_id]])-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---