2

I'm using sequel. In my app.rb, I wrote

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

Layout.erb

<form action="/search" method="get">
  <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 %>

And to the blog_model.rb in post class this:

def self.search(query)
  #where(:title, query) -> This would return an exact match of the query
  where("title like ?", "%#{query}%") 
end

And I'm getting this :LocalJumpError at /search no block given (yield). So what to do or have I done this code correctly ? Thanks in advance.

Thiago Lewin
  • 2,810
  • 14
  • 18
endritgr
  • 21
  • 2
  • Could you post the whole error message from the log please? Also you've shown us the method `search()` that you're not even using anywhere, you're also using `find()` where you should be using `where()` in your first snippet. – Mike Campbell Nov 21 '13 at 10:43

1 Answers1

2

I guess the problem is the name of erb file, layout.erb.

Sinatra always search for a layout.erb, if you not explicit indicate other layout file, that will handle the page template. This file has the form:

<!doctype html>
<html>
<head>
...
<body>
...
  <%= yield %> insert the content here
...
</html>

There are two solutions:

  1. Rename the layout.erb file.
  2. Replace the erb call by: erb :layout, layout: false
Thiago Lewin
  • 2,810
  • 14
  • 18