themen scope+ fix search

This commit is contained in:
Andreas Stephanides
2014-10-21 13:29:42 +02:00
parent ba8a20c3d1
commit 42ecb7dbcb
4 changed files with 18 additions and 13 deletions

View File

@@ -23,9 +23,9 @@ class ThemengruppenController < ApplicationController
def show
@themengruppe = Themengruppe.find(params[:id])
if can? :showdraft , Thema
@themen = @themengruppe.themen.order(:priority).reverse
@themen = @themengruppe.themen
else
@themen = @themengruppe.themen.where(:isdraft=>false).order(:priority).reverse
@themen = @themengruppe.themen.public
end
@toolbar_elements = []
@toolbar_elements << {:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t("themengruppe.manage"), :path=>themengruppe_verwalten_path(@themengruppe)} if can? :edit, @themengruppe

View File

@@ -21,7 +21,8 @@ include Rails.application.routes.url_helpers
validates :themengruppe, :presence => true
validates :title, :presence => true
validates :text, :presence => true
scope :public, where(:isdraft=>false)
default_scope order(:priority).reverse_order
scope :search, ->(query) {where("text like ? or title like ?", "%#{query}%", "%#{query}%")}
scope :outdated, -> {includes(:translations).where("thema_translations.updated_at<?",2.month.ago).where("thema_translations.locale"=>I18n.t.locale)
}

View File

@@ -1,17 +1,20 @@
<div class="content-wrap content-column">
<p>
<%= semantic_form_for :search,:remote=>true, :url=>search_home_index_path, :html=>{:id=>"search_form",:class=>"navbar-search", :method=>'get'} do |f| %>
<%= f.input :query, :input_html => { :name => 'query' } , :label=>false, :class=>"search-query" %>
<%= f.actions do %>
<%= f.action :submit, :as => :input %>
<% end %>
<script>
$( document ).ready(function() {
$("#search_query").bind("keyup", function(event){
$("#search_form").submit();
});
$("#search_query").value="df"
});
</script>
<% end %>
</p>
<p>
<div id="searchresults">
<%= render :partial=>"home/search_results" %>
</div>
</p>
</div>

View File

@@ -34,8 +34,9 @@
<div class="span6">
<!--<b><%= I18n.t("themengruppe.themen") %></b>
--><ul>
<% themengruppe.themen.where(" (NOT hidelink) and ( NOT isdraft) ").order(:priority).reverse.each do |t| %>
-->
<ul>
<% themengruppe.themen.where(:hidelink=>false).where(:isdraft=>false).each do |t| %>
<li>
<%= render t %>
</li>