On Thu, Aug 20, 2009 at 10:03 AM, Jeffrey L. Taylor <[email protected]>wrote:
> > Quoting karthik k <[email protected]>: > > Hi guys > > > > My client asked me to do all the Model.find() in Model class i.e all > > database interaction should be in model class and not in controller > > I don't know how to do that > > > > I need to pass details from html to model and do database work and send > back > > to view > > > > I need some help > > > > Any sample link or any advice ? > > > > Uhh, get a new client? If the client knows enough to dictate that level of > programming, either they don't need you or you don't need them. > > But less cynically, ask them what they are trying to accomplish by this. > Some > guru told them the "One True Way"? It may be reasonable to require all SQL > be > in the model class. The whole purpose of the find() method is to program > database access in Ruby without knowing SQL. > > The crude, ask no questions response is to take pluck out every find() call > and a reasonable amount of context in the controller and wrap it in a > method > in the model and call that. > > But, I would really try and get some clarification on why and what they > expect > to accomplish by this change. On the face of it, it seems very > unreasonable. > > HTH, > Jeffrey > Hi Jeffrey thank you we have lot of database interaction in the controller e.g def searchagency @status=params[:status] #...@status @agency=params[:agency][:agency_id] #...@agency @contract=params[:agency][:contracts_id] #...@contract @state=params[:agency][:state_id] #...@state if @status=='deleted' if [email protected]? && [email protected]? && @agency.blank? @agencies=Agency.all(:joins=>:contracts, :select=>"distinct agencies.*",:conditions=>["contract_id = ? and agencies.state_id =? and agencies.deleted=?",@contract,@state,1]) render :partial=>"agencysearchdisplay" elsif [email protected]? && [email protected]? && @contract.blank? @agencies=Agency.all(:joins=>:contracts, etc The above method is in controller so i need to write all the below code in model if [email protected]? && [email protected]? && @agency.blank? @agencies=Agency.all(:joins=>:contracts, :select=>"distinct agencies.*",:conditions=>["contract_id = ? and agencies.state_id =? and agencies.deleted=?",@contract,@state,1]) render :partial=>"agencysearchdisplay" elsif [email protected]? && [email protected]? && @contract.blank? @agencies=Agency.all(:joins=>:contracts, and just retrieve the result and display in html I need to write a method in model and access it from controller This is what we need Guide me -- Karthik.k Mobile - +91-9894991640 > > --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

