Ruby – Simple search using DataMapper and Sinatra

I am generally new to Ruby and backend development. That being said, I am trying to create a simple search form. I use Sinatra as the framework and Datamapper as my ORM .What is the best way to do this? Below is my architecture. I want the search operation to search for tiles and categories at the same time.

require'sinatra'
require'datamapper'
< br />
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/cal.db")

class Event
include DataMapper::Resource

property :id, Serial
property :title, String
property :text, Text
property :contact_name, String
property :contact_email, String< br /> property :location, String
property :event_start_time, String
property :event_end_time, String
property :category, String
property :created_at, DateTime
property: approved, Boolean, :default => false

end

DataMapper.auto_upgrade!


post'/search' do
@results = Event.all
erb :layout
end

============
layout.erb

< p>







<% if @results %>

<%@ results.each do |r|%>



<%end%>
<%=r.title%>

<% end %>

The most basic search query might look like this:

@events = Event.all(:title.like => "%#{params[ :query]}%") | Event.all(:category.like => "%#{params[:query]}%")

Back-end development are generally newbies. Having said that, I am trying to create a simple search form. I use Sinatra as the framework and Datamapper as my ORM. What is the best way to do this? Below is my architecture. I want the search operation to search for tiles and categories at the same time.

require'sinatra'
require'datamapper'
< br />
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/cal.db")

class Event
include DataMapper::Resource

property :id, Serial
property :title, String
property :text, Text
property :contact_name, String
property :contact_email, String< br /> property :location, String
property :event_start_time, String
property :event_end_time, String
property :category, String
property :created_at, DateTime
property: approved, Boolean, :default => false

end

DataMapper.auto_upgrade!


post'/search' do
@results = Event.all
erb :layout
end

============
layout.erb

< p>







<% if @results %>

<%@results. each do |r|%>



<%end%>
<%=r.title%>

<% end %>

The most basic search query might look like this:

@events = Event.all(:title.like => "%#{params[:query]}%") | Event.all(:category .like => "%#{params[:query]}%")

Leave a Comment

Your email address will not be published.