开发者

Auto_complete_for question

I've recently installed this plugin, and I meant to create a Tag field with it, like StackOverFlow does.

When I put the following syntax on my AnnouncementsController(I want to tag announcements) it works great:

  auto_complete_for :announcement, :title
  protect_from_forgery :only => [:create, :delete, :update]

Also, I had to add the routes syntax as well to make it work:

map.resources :announcements, :collection => {:auto_complete_for_announcement_title => :get }

Now, when I try to accomplish the same with the tags, at the time I create a new announcement, I simply replace the word "announcement" for "tag" and "title" for "name", and it won't work. Tag makes reference for my Tags table at the database.

The error says the following:

<h1>   ActiveRecord::RecordNotFound

    in AnnouncementsController#show    </h1> 
<pre>Couldn't find Announcement with ID=auto_complete_for_tag_name</开发者_运维百科pre>

Can anybody tell me what I'm doing wrong?

Thanks, Brian


In your view you probably want to change:

<%= text_field_with_auto_complete :announcement, :title %>

to:

<%= text_field_with_auto_complete :tag, :name %>

to make it work, take another look at the error it's giving, it's still calling announcement.

--- edit:

from autocomplete source:

 def text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})


Well, I finally got the answer to my problem.

I was missing the following at routes.rb:

  map.auto_complete '/:controller/:action',
     :requirements => { :action => /auto_complete_for_\S+/ },
     :conditions => { :method => :get }

My new question now it works is the following:

What if I wanted to multi-tag an announcements, for example: "Ruby, C#". Should I change the plugin's logic or is there a functionality to make this work? Cause right now, it will check for the text_field text, not discriminating a new word after a comma or any kind of separator.

Thanks, Brian

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜