#488 ✓invalid
oldlibmike

name_one function does not work with new records

Reported by oldlibmike | August 15th, 2009 @ 09:05 PM

Using hobo 0.8.8 with rails 2.3.3, the name_one function works perfectly when editing existing records.
When creating new records, the name_one continually throws an error:
ActionController::RoutingError (No route matches "/thiss/complete_pick_contact" with {:method=>:get}):

Code in controller:
autocomplete :pick_contact do hobo_completions :sortname, Contact end

Code in application.dryml:
<!-- Sale form -->

I saw a few references to similar errors in the past but never with a resolution. I asked on the google forum if ANYONE had used name_one successfully with new records and got no replies.

This appears to be a bug. Please let me know what other information I should provide.

Thanks,
Mike

Comments and changes to this ticket

  • Bryan Larsen

    Bryan Larsen August 17th, 2009 @ 10:32 PM

    It looks to me like @sale is nil. can you please post your edit and create actions?

  • Bryan Larsen

    Bryan Larsen August 18th, 2009 @ 12:10 AM

    • State changed from “new” to “invalid”

    I think I'm going to drastically simplify the agility tutorial, it's leading people astray. Try this:

    In your Contacts controller (NOT your Sales controller)

    autocomplete :sortname
    

    And

    <contact-view:>
      <name-one completer="sortname"/>
    </contact-view:>
    

    I've updated the name-one documentation. Here's a preview:

    An <input type="text"> with auto-completion. Allows the user to chose the target of a belongs_to association by name.

    This tag relies on an autocompleter being defined in a controller. A simple example:

    <form with="&ProjectMembership.new">
      <name-one:user>
    </form>
    
    class ProjectMembership < ActiveRecord::Base
      hobo_model
      belongs_to :user
    end
    
    class User < ActiveRecord::Base
      hobo_user_model
      has_many :project_memberships
    end
    
    class UsersController < ApplicationController
      autocomplete
    end
    

    The query string is what the user types into the control, the route to the completer action is specified in the attributes to the name-one tag, and the others are specified in your controller.

    The route used by the autocompleter looks something like /users/complete_name. The first part of this route is specified by the complete-target attribute, and the second part is specified by the completer attribute.

    complete-target specifies the controller for the route. It can be specified by either supplying a model class or a model. If a model is supplied, the id of the model is passed as a parameter to the controller. (?id=7, for example) The default for this attribute is the class of the context. In other words, the class that contains the has_many / has_one, not the class with the belongs_to.

    completer specifies the action for the route. name-one prepends complete_ to the value given here. This should be exactly the same as the first parameter to autocomplete in your controller. As an example: autocomplete :email_address would correspond to completer="email_address". The default for this attribute is the name field for the model being searched, which is usually name, but not always.

    The query string is passed to the controller in the query parameter. (?query=hello for example).

    For more information on how to customize the controller, see the controller manual

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages