lib/carte/server.rb in carte-server-0.0.23 vs lib/carte/server.rb in carte-server-0.0.24

- old
+ new

@@ -39,20 +39,24 @@ if order == 'random' cards = Card.random else cards = Card.send(order, sort) end + conditions = [] if title = params[:title] - cards = cards.any_of({title: /#{title}/i}) + conditions << {title: /#{title}/i} end + if content = params[:content] + conditions << {content: /#{content}/i} + end + if conditions.size > 0 + cards = cards.any_of(conditions) + 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}/i}) - end cards = cards.paginate(per_page: 9, page: params[:page]) end def markdown2html(markdown) renderer = Redcarpet::Render::HTML.new(filter_html:true) @@ -66,10 +70,10 @@ end get '/cards.json' do cards = search(params) { - cards: cards.as_json(only: %w(title content version tags)), + cards: cards.map {|card| card.as_json(only: %w(title content tags)).update(version: card.version) }, pagination: {current_page: cards.current_page, total_pages: cards.total_pages, total_entries: cards.total_entries} }.to_json end get '/cards/:title.json' do