problems in using search function in rails -
i trying simple search function. function in module. have 2 columns: title , description. error. instead of posts need have select "title" in there.
def self.search(search) if search find(:all, :conditions => ['name ?', "%#{search}%"]) else find(:all) end end
the error is:
sqlite3::sqlexception: no such column: name: select "posts".* "posts" (name '%first%')
update:
here index.html.erb file. have used form , listed posts along content. how change file display searched item? should listed. not able understand how this. ideas?
<h1>our blog</h1> <%= form_tag posts_path, :method => 'get' %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "search", :name => nil %> </p> <% end %> <% @posts.each |post| %> <h2><%= link_to post.title,post %></h2> <p><%= post.content %></p> <hr /> <%= link_to "add new post", new_post_path %> <% end %>
you have no column name
in table posts
think want search on title
& description
try following
find(:all, :conditions => ['title ? or description ?', "%#{search}%", "%#{search}%"])
Comments
Post a Comment