Relatively new to Ruby but sticking with it, however I really need some help on passing parameters. I have a table of risks with a status field (values = Open Closed or Parked.) I have a view where user can enter the Status they wnat to retrieve all matching records for. View Code:- <form action="/risk/liststatus2"> Status <input type="text" name="Status" size="20"><p> <input type="submit"> </form> In the Risk Controller I have the following Code:- def liststatus2 @found = Risk.liststatus2 end and finally in the Model I have the following code:- def self.liststatus2 find(:all, :conditions => "Status = ?", @Status) end Obviously my Model code is wrong since if I use the following code:- find(:all, :conditions => "Status = ''Open''") i.e. hard-coding the value ''Open'' then it works fine. So, in short, can someone please advise the syntax for passing the Status parameter into the model to retrieve the records the user wants. I have spent alot of time trying to sort this and learned alot of other useful stuff in the process...so I''m not just running for help straight away. Having said that I really do need some assitance. Any help gratefully recieved. Thanks Martyn -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Martyn, Martyn Elmy-liddiard wrote:> Obviously my Model code is wrongNo offense intended, but there''re problems with all your code.> <form action="/risk/liststatus2"> > Status <input type="text" name="Status" size="20"><p> > <input type="submit"> > </form>You''re hardcoding your form instead of using eRb. Rails will have a hard time figuring out what you''re asking it to do. You''ll need to decide whether you want your params bound to a model or not: text_field vs. text_field_tag. > In the Risk Controller I have the following Code:-> def liststatus2 > @found = Risk.liststatus2 > endParams get passed back to the controller in a hash. In the case above, the value is coming back in a param you''d address like: @found = params[:Status]> and finally in the Model I have the following code:- > def self.liststatus2 > find(:all, :conditions => "Status = ?", @Status) > endThe value is in @found. hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Martyn, > > Martyn Elmy-liddiard wrote: > >> Obviously my Model code is wrong > > No offense intended, but there''re problems with all your code. > >> <form action="/risk/liststatus2"> >> Status <input type="text" name="Status" size="20"><p> >> <input type="submit"> >> </form> > > You''re hardcoding your form instead of using eRb. Rails will have a > hard > time figuring out what you''re asking it to do. You''ll need to decide > whether you want your params bound to a model or not: text_field vs. > text_field_tag. > > > In the Risk Controller I have the following Code:- >> def liststatus2 >> @found = Risk.liststatus2 >> end > > Params get passed back to the controller in a hash. In the case above, > the > value is coming back in a param you''d address like: > > @found = params[:Status] > >> and finally in the Model I have the following code:- >> def self.liststatus2 >> find(:all, :conditions => "Status = ?", @Status) >> end > > The value is in @found. > > hth, > BillAbsolutely no offence taken!...I''m always happy to l;earn from others. Unfortunately I dont quite understand your response. Would it be possible for you to show me an example of how you would code this same requirement. I can then decode that and understand how the best way to do it is. Much appreciated! -- 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 -~----------~----~----~----~------~----~------~--~---