lib/carte/server.rb in carte-server-0.0.9 vs lib/carte/server.rb in carte-server-0.0.10

- old
+ new

@@ -2,20 +2,22 @@ require 'sinatra/namespace' require 'mongoid' require 'mongoid_auto_increment_id' require 'will_paginate_mongoid' require 'mongoid-simple-tags' +require 'mongoid/geospatial' require 'carte/server/validators' require 'carte/server/models' module Carte class Server < Sinatra::Base use Rack::Deflater register Sinatra::Namespace include Carte::Server::Models configure do + set :protection, :except => :path_traversal set :views, File.join(File.dirname(__FILE__), 'server/views') set :public_folder, 'public' set :script_path, '/app.js' end @@ -27,21 +29,22 @@ def search(params) order = (params[:order] && %w(asc desc random).include?(params[:order])) ? params[:order] : 'desc' sort = (params[:sort] && %w(title created_at updated_at).include?(params[:sort])) ? params[:sort] : 'updated_at' if order == 'random' - return Card.sample(9) + cards = Card.random + else + cards = Card.send(order, sort) end - cards = Card.send(order, sort) if title = params[:title] - cards = cards.any_of({title: /#{title}/}) + cards = cards.any_of({title: /#{title}/i}) end if params[:tags] tags = params[:tags].split(',') cards = cards.tagged_with_all(tags) end if content = params[:content] - cards = cards.any_of({content: /#{content}/}) + cards = cards.any_of({content: /#{content}/i}) end cards = cards.paginate(per_page: 9, page: params[:page]) end end