I have tried to get through this error with no luck. In a form I have a user enter a title and then search the database for any similar titles. I need help with this. It''s like the information isn''t being passed through. Here is my information. I am using Rails 2.1 with nifty_scaffold. First I changed my route routes.rb map.resources :titles, :collection => { :find_similar => :get } new.html.erb <% title "New Title" %> <% form_for @title, :url => { :action => :find_similar } do |f| %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <p><%= f.submit "Search" %></p> <% end %> <p><%= link_to "Back to List", titles_path %></p> titles_controller.rb def find_similar @searchkey = params[:name] @title = Title.find(:all, :conditions => ["name like ?", ''%''+@searchkey+''%'']) end Parameters: {"commit"=>"Search", "title"=>{"name"=>"one day"}, "authenticity_token"=>"ec64448f9d39d29dd3dbafd1a1a31415ea165bdb"} TypeError in TitlesController#find_similar can''t convert nil into String app/controllers/titles_controller.rb:48:in `+'' app/controllers/titles_controller.rb:48:in `find_similar'' -- 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 Quincy, have you tried the following? def find_similar @searchkey = params[:title][:name] ... end On Jul 12, 8:24 pm, Quincy Central_tex <rails-mailing-l...@andreas- s.net> wrote:> I have tried to get through this error with no luck. In a form I have a > user enter a title and then search the database for any similar titles. > I need help with this. It''s like the information isn''t being passed > through. Here is my information. I am using Rails 2.1 with > nifty_scaffold. First I changed my route > > routes.rb > map.resources :titles, :collection => { :find_similar => :get } > > new.html.erb > <% title "New Title" %> > > <% form_for @title, :url => { :action => :find_similar } do |f| %> > <p> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </p> > <p><%= f.submit "Search" %></p> > <% end %> > > <p><%= link_to "Back to List", titles_path %></p> > > titles_controller.rb > def find_similar > @searchkey = params[:name] > @title = Title.find(:all, > :conditions => ["name like ?", > ''%''+@searchkey+''%'']) > end > > Parameters: > > {"commit"=>"Search", > "title"=>{"name"=>"one day"}, > "authenticity_token"=>"ec64448f9d39d29dd3dbafd1a1a31415ea165bdb"} > > TypeError in TitlesController#find_similar > can''t convert nil into String > app/controllers/titles_controller.rb:48:in `+'' > app/controllers/titles_controller.rb:48:in `find_similar'' > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
gsterndale wrote:> Hi Quincy, > > have you tried the following? > > def find_similar > @searchkey = params[:title][:name] > ... > end > > > On Jul 12, 8:24 pm, Quincy Central_tex <rails-mailing-l...@andreas-That did it! Thanks gsterndale! Please explain whats happening here. I haven''t seen this in any documentation. -- 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 you look at the HTML generated by your new.html.erb template you''ll see how form_for names your input fields. For example: <% form_for @title, :url => { :action => :find_similar } do |f| %> <%= f.text_field :name %> <% end %> would generate something like: <form action="/titles/find_similar" class="..." id="..." method="post"> <input id="title_name" name="title[name]" type="text" /> </form> Note the brackets [] around "name". As you know, Rails puts the submitted form field names and values into a Hash called "params". When a form field with brackets is submitted, Rails interprets the value of the parameter "title" as a Hash with a key called "name". The value of that field is assigned to that key. The result is a nested Hash, exactly what you pasted in your first post. { "commit"=>"Search", "title"=>{ "name"=>"one day" }, "authenticity_token"=>"ec64448f9d39d29dd3dbafd1a1a31415ea165bdb" } http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001737 On Jul 12, 11:51 pm, Quincy Ctx <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> gsterndale wrote: > > Hi Quincy, > > > have you tried the following? > > > def find_similar > > @searchkey = params[:title][:name] > > ... > > end > > > On Jul 12, 8:24 pm, Quincy Central_tex <rails-mailing-l...@andreas- > > That did it! Thanks gsterndale! Please explain whats happening here. I > haven''t seen this in any documentation. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Got it!! thanks -- 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 -~----------~----~----~----~------~----~------~--~---