How to do a Sequel query with 'like'?

ruby, sequel, sinatra

Solution

Try

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

Problem

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'.

Original source