can't convert nil into String

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'

Hi Quincy,

have you tried the following?

def find_similar     @searchkey = params[:title][:name]     ... end

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.

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

Got it!! thanks