I''m just picking up rails...I''ve got a few questions. First, I''d like to get some input and parrot it back. I''m trying the following in my .rhtml file but it isn''t working. What am I missing here? <html> <head> <title>Search</title> </head> <body> <h1>Search for Filings</h1> <p> Use this page to find filings from a given company or organization. </p> <form action="" method="POST"> <p><b>Search for Companies Filings: </b><input type="text" name="companyName" value="<%= @companyToSearchFor %>" size="50"/> </form> <p> Searching for...<%= @companyToSearchFor %> </p> </body> </html> _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
It would be good to know what your controller/model code looks like, what you expect for this code to do, and what it does in practice (errors, etc). Also whether you''re using layouts, what the rhtml file is, etc. There''s a number of people here who are glad to help if enough information regarding the problem is given. Brian On Tue, 15 Feb 2005 22:23:50 -0600, John Marsan <jmarsan-JxUet7QE5mQXhy9q4Lf3Ug@public.gmane.org> wrote:> > I''m just picking up rails...I''ve got a few questions. > > First, I''d like to get some input and parrot it back. I''m trying the > following in my .rhtml file but it isn''t working. What am I missing here? > > <html> > <head> > <title>Search</title> > </head> > <body> > <h1>Search for Filings</h1> > <p> > Use this page to find filings from a given company or organization. > </p> > <form action="" method="POST"> > <p><b>Search for Companies Filings: </b><input type="text" > name="companyName" value="<%= @companyToSearchFor %>" size="50"/> > </form> > <p> > Searching for...<%= @companyToSearchFor %> > </p> > > </body> > </html> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- The years ahead pick up their dark bags. They move closer. There''s a slight rise in the silence then nothing. -- (If you''re receiving this in response to mail sent to bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, but mail will be forwarded here indefinitely)
The controller looks like: class FilingController < ApplicationController scaffold :filing def search @filings = Filing.find_all("company_name = ''''") end end The .rhtml was posted below. What I''m trying to do is get some input and use it as a filter/search on a simple database with just two fields, one being company name. So, I''d like to get the user to type in a company name and then display just those records matching the name. I''m not getting any errors with this code - it just doesn''t do what I''d expect which is to print out what ever was entered into the text box - the data I enter is not printed out. Thanks for the help. John ----- Original Message ----- From: "Brian L." <zorander-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> Sent: Tuesday, February 15, 2005 11:08 PM Subject: Re: [Rails] Beginners Question> It would be good to know what your controller/model code looks like, > what you expect for this code to do, and what it does in practice > (errors, etc). Also whether you''re using layouts, what the rhtml file > is, etc. There''s a number of people here who are glad to help if > enough information regarding the problem is given. > > Brian > > > > On Tue, 15 Feb 2005 22:23:50 -0600, John Marsan <jmarsan-JxUet7QE5mQXhy9q4Lf3Ug@public.gmane.org> > wrote: >> >> I''m just picking up rails...I''ve got a few questions. >> >> First, I''d like to get some input and parrot it back. I''m trying the >> following in my .rhtml file but it isn''t working. What am I missing >> here? >> >> <html> >> <head> >> <title>Search</title> >> </head> >> <body> >> <h1>Search for Filings</h1> >> <p> >> Use this page to find filings from a given company or organization. >> </p> >> <form action="" method="POST"> >> <p><b>Search for Companies Filings: </b><input type="text" >> name="companyName" value="<%= @companyToSearchFor %>" size="50"/> >> </form> >> <p> >> Searching for...<%= @companyToSearchFor %> >> </p> >> >> </body> >> </html> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > -- > The years ahead pick up their dark bags. > They move closer. There''s a slight rise in the silence > > then nothing. > -- > (If you''re receiving this in response to mail sent to > bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, > but mail will be forwarded here indefinitely) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
John, On 16.2.2005, at 07:28, John Marsan wrote:> The controller looks like: > > class FilingController < ApplicationController > > scaffold :filing > > def search > @filings = Filing.find_all("company_name = ''''") > end > end1. You have to separate the process between normal page load (get) and a form post (post) since you''re using the same action for both (which is not a bad idea at all). 2. You don''t set the var @companyToSearchFor anywhere. 3. You don''t have an action specified for the form. I''m not sure if that defaults to the current page, tho. 4. Where do you want the results to show up, and how? Here''s a bit of help to get you further: def search case @request.method when :get # this is the normal page load @companyToSearchFor = "" render when :post # this is what happens after you post the form @companyToSearchFor = @params["companyName"] @filings = Filing.find_all(["company_name = ?", @companyToSearchFor]) end end I don''t fully get what you''re trying to accomplish with the view below but it should now more or less work. You probably want to show the filings in there, too, tho. You might also want to take a closer look at helper functions that help you build form and input tags: http://rails.rubyonrails.com/classes/ActionView/Helpers/TagHelper.html http://rails.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html //jarkko>>> >>> <html> >>> <head> >>> <title>Search</title> >>> </head> >>> <body> >>> <h1>Search for Filings</h1> >>> <p> >>> Use this page to find filings from a given company or organization. >>> </p> >>> <form action="" method="POST"> >>> <p><b>Search for Companies Filings: </b><input type="text" >>> name="companyName" value="<%= @companyToSearchFor %>" size="50"/> >>> </form> >>> <p> >>> Searching for...<%= @companyToSearchFor %> >>> </p> >>> >>> </body> >>> </html>-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko - Thanks for the help! John, On 16.2.2005, at 07:28, John Marsan wrote:> The controller looks like: > > class FilingController < ApplicationController > > scaffold :filing > > def search > @filings = Filing.find_all("company_name = ''''") > end > end1. You have to separate the process between normal page load (get) and a form post (post) since you''re using the same action for both (which is not a bad idea at all). 2. You don''t set the var @companyToSearchFor anywhere. 3. You don''t have an action specified for the form. I''m not sure if that defaults to the current page, tho. 4. Where do you want the results to show up, and how? Here''s a bit of help to get you further: def search case @request.method when :get # this is the normal page load @companyToSearchFor = "" render when :post # this is what happens after you post the form @companyToSearchFor = @params["companyName"] @filings = Filing.find_all(["company_name = ?", @companyToSearchFor]) end end I don''t fully get what you''re trying to accomplish with the view below but it should now more or less work. You probably want to show the filings in there, too, tho. You might also want to take a closer look at helper functions that help you build form and input tags: http://rails.rubyonrails.com/classes/ActionView/Helpers/TagHelper.html http://rails.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html //jarkko>>> >>> <html> >>> <head> >>> <title>Search</title> >>> </head> >>> <body> >>> <h1>Search for Filings</h1> >>> <p> >>> Use this page to find filings from a given company or organization. >>> </p> >>> <form action="" method="POST"> >>> <p><b>Search for Companies Filings: </b><input type="text" >>> name="companyName" value="<%= @companyToSearchFor %>" size="50"/> >>> </form> >>> <p> >>> Searching for...<%= @companyToSearchFor %> >>> </p> >>> >>> </body> >>> </html>