Autocomplete Error Question - Ruby on Rails
Posted
by bgadoci
on Stack Overflow
See other posts from Stack Overflow
or by bgadoci
Published on 2010-04-14T04:37:42Z
Indexed on
2010/04/14
4:43 UTC
Read the original article
Hit count: 374
I have built a very simple blog application using Ruby on Rails. New to both Ruby and Rails so excuse the stupid questions.
I currently have two tables that relate to this question. I have a Post table and a Tag table. Basically I set it up such that Post has_many :tags
and Tag belongs_to :post
. I am using AJAX to process and display the tags in the show view of the post.
I installed the auto_complete plugin and I am getting an error when I enter the letters in the text_field_with_auto_complete for tag creation. My suspicion is this is because the form is a remote_form_for or something I am doing wrong in the routes.rb. Here is the error and code:
Error
Processing PostsController#show (for 127.0.0.1 at 2010-04-13 23:25:46) [GET]
Parameters: {"tag"=>{"tag_name"=>"f"}, "id"=>"auto_complete_for_tag_tag_name"}
Post Load (0.1ms) SELECT * FROM "posts" WHERE ("posts"."id" = 0)
ActiveRecord::RecordNotFound (Couldn't find Post with ID=auto_complete_for_tag_tag_name):
app/controllers/posts_controller.rb:22:in `show'
Rendered rescues/_trace (26.0ms)
Rendered rescues/_request_and_response (0.2ms)
Rendering rescues/layout (not_found)
remote_form_for located in /views/posts/show.html.erb
<% remote_form_for [@post, Tag.new] do |f| %>
<p>
<%= f.label :tag_name, "Tag" %><br/>
<%= text_field_with_auto_complete :tag, :tag_name, {}, {:method => :get} %>
</p>
<p><%= f.submit "Add Comment" %></p>
<% end %>
tags_controller.rb (I'll spare you all the actions but added the following here)
auto_complete_for :tag, :tag_name
routes.rb
map.resources :posts, :has_many => :comments
map.resources :posts, :has_many => :tags
map.resources :tags, :collection => {:auto_complete_for_tag_tag_name => :get }
© Stack Overflow or respective owner