Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 在rails中使用搜索函数的问题_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 在rails中使用搜索函数的问题

Ruby on rails 3 在rails中使用搜索函数的问题,ruby-on-rails-3,Ruby On Rails 3,我正在尝试做一个简单的搜索功能。这是模块中的功能。我有两列:标题和描述。但是我犯了一个错误。我需要在那里选择“标题”,而不是帖子 def self.search(search) if search find(:all, :conditions => ['name LIKE ?', "%#{search}%"]) else find(:all) end end 我得到的错误是: SQLite3::SQLException: no such column: nam

我正在尝试做一个简单的搜索功能。这是模块中的功能。我有两列:标题和描述。但是我犯了一个错误。我需要在那里选择“标题”,而不是帖子

def self.search(search)
  if search
    find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
  else
    find(:all)
  end
end
我得到的错误是:

SQLite3::SQLException: no such column: name: SELECT "posts".* FROM "posts" WHERE (name LIKE '%first%')
更新:

这是我的index.html.erb文件。我基本上使用了一个表单,列出了所有帖子及其内容。如何更改文件以仅显示搜索的项目?最初应列出所有项目。我不知道该怎么做。有什么想法吗

<h1>Our Blog</h1>
<%= form_tag posts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>

<% @posts.each do |post| %>
  <h2><%= link_to post.title,post %></h2>
  <p><%= post.content %></p>
  <hr />
  <%= link_to "Add a new post", new_post_path %>
<% end %>
我们的博客
'获取'执行%>

零%>



您的表中没有列
名称
帖子我想您需要搜索
标题
说明
,因此请尝试以下内容

find(:all, 
     :conditions => ['title LIKE ? OR description like ?', "%#{search}%", "%#{search}%"])

如果您对AR不说话,它将搜索整行: