How to do a Sequel query with 'like'?

I'm trying to implement a form to search through the title of my posts.

This is the controller code:

post '/search'  do
@results = Post.all(:Title.like => "%#{params[:query]}%")
erb :layout 
end

This is the layout.erb code:

<form action="/search" method="post">
 <input type="text" name="query"/><br />   
 <input type="submit" />
</form>
<% if @results %>
 <table>
  <%@results.each do |r|%>
  <tr valign="top">
  <td><%=r.Title%></td>
  </tr>
  <%end%>
 </table>
<% end %>

I get an error saying 'undefined method `like' for :Title:Symbol'

Any idea please?

Answers


Try

@results = DB[:posts].where(Sequel.like(:Title, "%#{params[:query]}%"))


Need Your Help

Error While Installing IIS 6 Metabase and IIS 6 Configuration Compatibility

windows-7 iis-6

While I'm installing the IIS 6 Metabase and IIS 6 Configuration Compatibility, I got an error as below, Please any one have idea about it?

blueprint of blueprints (Flask)

python web-services web-applications flask blueprint

I have a series of blueprints I'm using, and I want to be able to bundle them further into a package I can use as seamlessly as possible with any number of other applications. A bundle of blueprint...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.