Gene Kahn
2006-Aug-06 04:29 UTC
[Rails] View passing empty or no value to controller -- help
Hi, I have the following view: <%= start_form_tag ( { :action => ''find'' }, :method => ''get'') %> <p> <%= text_field_tag :lemma, params[:lemma] %> </p> <%= link_to "Find It", :class => "submit" %> <%= end_form_tag %> And the following find action in the controller: def find lemma = Lemma.find_by_lemma(params[:lemma]) if lemma redirect_to (:controller => "lemma", :action => "show") else flash.now[:notice] = "Unable to find lemma: #{lemma}." end end It appears that the view does not pass back any value to the controller, or passes an empty value, because the flash notice does not print any value of the lemma, thus: Unable to find lemma: . What am I missing? Thanks for the help, gk -- Posted via http://www.ruby-forum.com/.
Mark Reginald James
2006-Aug-07 04:28 UTC
[Rails] Re: View passing empty or no value to controller -- help
Gene Kahn wrote:> def find > lemma = Lemma.find_by_lemma(params[:lemma]) > if lemma > redirect_to (:controller => "lemma", :action => "show") > else > flash.now[:notice] = "Unable to find lemma: #{lemma}." > end > end > > It appears that the view does not pass back any value to the controller, > or passes an empty value, because the flash notice does not print any > value of the lemma, thus: > > Unable to find lemma: .You want: flash.now[:notice] = "Unable to find lemma: #{params[:lemma]}." -- We develop, watch us RoR, in numbers too big to ignore.
Gene Kahn
2006-Aug-07 06:01 UTC
[Rails] Re: View passing empty or no value to controller -- help
Mark Reginald James wrote:> Gene Kahn wrote: > >> or passes an empty value, because the flash notice does not print any >> value of the lemma, thus: >> >> Unable to find lemma: . > > You want: > > flash.now[:notice] = "Unable to find lemma: #{params[:lemma]}." > > -- > We develop, watch us RoR, in numbers too big to ignore.Hi, Thank you, yes, that makes sense. However it all the more confirmed that the controller action is not getting any value back from the Find view since the notice does not print any return value. Thanks for taking the time to reply. gk -- Posted via http://www.ruby-forum.com/.
Max Muermann
2006-Aug-07 06:37 UTC
[Rails] View passing empty or no value to controller -- help
Try def find p params ... and look at the server output - do any parameters show up? Also have a look at the html source generated by text_field. Max On 8/6/06, Gene Kahn <kublaikhan55@hotmail.com> wrote:> Hi, > I have the following view: > > <%= start_form_tag ( { :action => ''find'' }, :method => ''get'') %> > <p> > <%= text_field_tag :lemma, params[:lemma] %> > </p> > <%= link_to "Find It", :class => "submit" %> > <%= end_form_tag %> > > And the following find action in the controller: > > def find > lemma = Lemma.find_by_lemma(params[:lemma]) > if lemma > redirect_to (:controller => "lemma", :action => "show") > else > flash.now[:notice] = "Unable to find lemma: #{lemma}." > end > end > > It appears that the view does not pass back any value to the controller, > or passes an empty value, because the flash notice does not print any > value of the lemma, thus: > > Unable to find lemma: . > > What am I missing? Thanks for the help, > gk > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Gene Kahn
2006-Aug-07 08:18 UTC
[Rails] Re: View passing empty or no value to controller -- help
Max Muermann wrote:> Try > > def find > p params > ... > > and look at the server output - do any parameters show up? > > Also have a look at the html source generated by text_field. > > MaxDown below are some relevant lines from development.log. The where clause for the find sql is: (eng_lemmas."lemma" IS NULL ) Also, the url does not show the value to find (or that it is null): [http://localhost/eng_lemma/find?class=submit] I also added p params[:lemma] to the Find action, but the server.log is empty. Is that where it will send the output to? The helper text_field is expanded as: <p> <input id="lemma" name="lemma" type="text" /> </p> The values of name and type are correct. So it does look like the view is returning nothing or something that the controller interprets as null. (pulling my hair) Thanks, gk Processing EngLemmaController#find (for 127.0.0.1 at 2006-08-07 01:51:17) [GET] Session ID: ea3ac9c50cc7a0d7bf5830462e8292ab Parameters: {"class"=>"submit", "action"=>"find", "controller"=>"eng_lemma"} [4;36;1mSQL (0.015000) [0;1m SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = ''eng_lemmas''::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum [4;35;1mEngLemma Load (0.141000) SELECT * FROM eng_lemmas WHERE (eng_lemmas."lemma" IS NULL ) LIMIT 1 Rendering within layouts/application Rendering eng_lemma/find Completed in 0.17200 (5 reqs/sec) | Rendering: 0.01600 (9%) | DB: 0.15600 (90%) | 200 OK [http://localhost/eng_lemma/find?class=submit] -- Posted via http://www.ruby-forum.com/.
Michael Siebert
2006-Aug-07 08:30 UTC
[Rails] View passing empty or no value to controller -- help
2006/8/6, Gene Kahn <kublaikhan55@hotmail.com>:> > Hi, > I have the following view: > > <%= start_form_tag ( { :action => ''find'' }, :method => ''get'') %> > <p> > <%= text_field_tag :lemma, params[:lemma] %> > </p> > <%= link_to "Find It", :class => "submit" %> > <%= end_form_tag %>i''d guess the "find it" link does NOT submit the form. try sth like <%submit_tag(''Find It'') %> instead. should work -- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/69302e57/attachment.html
Gene Kahn
2006-Aug-07 08:53 UTC
[Rails] Re: View passing empty or no value to controller -- help
Michael Siebert wrote:> 2006/8/6, Gene Kahn <kublaikhan55@hotmail.com>: >> >> Hi, >> I have the following view: >> >> <%= start_form_tag ( { :action => ''find'' }, :method => ''get'') %> >> <p> >> <%= text_field_tag :lemma, params[:lemma] %> >> </p> >> <%= link_to "Find It", :class => "submit" %> >> <%= end_form_tag %> > > > i''d guess the "find it" link does NOT submit the form. try sth like <%> submit_tag(''Find It'') %> instead. should work > > > -- > Michael Siebert <info@siebert-wd.de> > > www.stellar-legends.de - Weltraum-Browsergame im Alpha-StadiumThat works! Strange, because in some of my other views, link_to ... :class = "submit" works. It''s been a struggle; I need a drink here. Thanks for the help. gk -- Posted via http://www.ruby-forum.com/.