Auto_complete through User.name

Xavier N. wrote:

On Tue, Sep 2, 2008 at 11:30 PM, Neil C.
[email protected] wrote:

If I comment out the render :inline => ‘<%=
model_auto_completer_result(@recipients, :name) %>’ I get the normal
layout back. Is it a problem with loading the
auto_complete_belongs_to_for as a before_filter?

Just remove the before_filter macro call, and make
auto_complete_belongs_to_for_invitation_recipient_name public.

That method is called automatically by the helper through Ajax when
the user enters something into the field. You typically won’t call it
explicitly.

We’re nearly there - it’ll be worth it, I’m sure! I’m just getting this;

ActionController::InvalidAuthenticityToken in
GroupsController#auto_complete_belongs_to_for_invitation_recipient_name
ActionController::InvalidAuthenticityToken

And my form partial looks like this;

<% @invitation = Invitation.new %>

<% form_for ([@group, @invitation]), :id => "invitation_form" do |f| %> <%= belongs_to_auto_completer :invitation, :recipient, :name %> <%= f.submit 'Send Invitation', :class => "action_button submit" %> <% end %>

Xavier N. wrote:

On Wed, Sep 3, 2008 at 11:40 PM, Neil C.
[email protected] wrote:

<% form_for ([@group, @invitation]), :id => “invitation_form” do |f|
%>
<%= belongs_to_auto_completer :invitation, :recipient, :name %>
<%= f.submit ‘Send Invitation’, :class => “action_button submit” %>
<% end %>

Hi Neil, that’s related to Ajax calls and the request from forgery
protection. Just google for
“ActionController::InvalidAuthenticityToken ajax”.

I couldn’t work out why I was getting the
ActionController::InvalidAuthenticityToken on this particular form_for,
even after doing some reading round. I tried two approaches, and neither
resolved the issue;

[1] <% form_for ([@group, @invitation]), :id => “invitation_form” do |f|
%>
[2] <% form_for :invitation, :url => group_invitations_path(@group) do
|f| %>

So, to skip the trial & error on the token problem, I commented out the
protect_from_forgery, just so I could get the auto_complete actually
working first, and I don’t seem to get any results back at all. I’m
still using the same set up as before and I did have the auto_complete
plugin working, so I know it’s not a problem with js. When I un-comment
the display=“none” on the hidden div, it seems as though it contains a
whole new DOM within the hidden div; the whole of another
application.html.erb seems to be hidden in there!

Any ideas left?

Xavier N. wrote:

On Sat, Aug 23, 2008 at 5:16 PM, Neil C.
[email protected] wrote:

I’m attempting an auto_complete by user.name, but it’s not as simple as
it sounds. I’ve followed the great Railscast on the topic, and I do have
the ajaxiness working just fine when I search by ID (I was doing this
for testing purposes - I don’t want users using IDs to find each other,
luckily). My auto_complete field needs to work the same as the GitHub
‘Collaborator’ addition form (or the Facebook search), whereby we find
the user by user.name. My problem is that the user.name attribute is
only a method in my user.rb, it is not a unique attribute, nor does it
exist in the users table. So, we can’t identify a user through it, we
need the ID.

model_auto_completer addresses this:

http://agilewebdevelopment.com/plugins/model_auto_completer

I happen to be the author but I’d recommend it if I wasn’t anyway.

Does model_auto_complete work with has_many :through relationships?
belongs_to relationhips work like a charm but I can’t seem to get
has_many :through relationships to work. Any examples available?

On Wed, Sep 3, 2008 at 11:40 PM, Neil C.
[email protected] wrote:

<% form_for ([@group, @invitation]), :id => “invitation_form” do |f|
%>
<%= belongs_to_auto_completer :invitation, :recipient, :name %>
<%= f.submit ‘Send Invitation’, :class => “action_button submit” %>
<% end %>

Hi Neil, that’s related to Ajax calls and the request from forgery
protection. Just google for
“ActionController::InvalidAuthenticityToken ajax”.