一个简单的搜索功能
routes:

  get "search" => 'articles#search'

view:

<%= form_tag('/search',method: :get,enforce_utf8: false) do -%>
  <div><%= search_field_tag "search" %></div>
  <div><%= submit_tag '搜索' %></div>
<% end -%>

cotroller:

  def search
    #render plain: params
    @articles = Article.search(params[:search])
  end

model:

  def self.search(search)
    where("title LIKE ? OR text LIKE ?", "%#{search}%","%#{search}%")
  end

天赢金创
338 声望21 粉丝

天赢金创,天赢金创,天赢金创,天赢金创,天赢金创,天赢金创天赢金创,天赢金创


引用和评论

0 条评论