Skip to content

Commit

Permalink
Result screen and search methods refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
aitor committed Apr 18, 2010
1 parent 825a15b commit 64764d3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
32 changes: 16 additions & 16 deletions app/controllers/municipios_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@ def show

end

def cities_by_query
search_by_query
end

def search
q = params[:q]

@results = Municipio.search(q)

meta :title => "Resultados de la búsqueda '#{q}' - lospresus.de",
:description => "Resultados de la búsqueda '#{q}' en lospresus.de",
:keywords => "presupuestos, ayuntamientos, gastos, ingresos, subvenciones, municipios, municipal, dinero público, gasto público"

search_by_query(:limit => 10)
render :layout => false
end

def search_for_compare
q = params[:q]

@results = Municipio.search(q)

meta :title => "Resultados de la búsqueda '#{q}' - lospresus.de",
:description => "Resultados de la búsqueda '#{q}' en lospresus.de",
:keywords => "presupuestos, ayuntamientos, gastos, ingresos, subvenciones, municipios, municipal, dinero público, gasto público"

search_by_query(:limit => 10)
render :layout => false
end

Expand Down Expand Up @@ -57,4 +47,14 @@ def find_muni
def year_context
@year = params[:year] || Date.today.year - 1
end
def search_by_query(options={})
q = params[:q]

@results = Municipio.search(q, options)

meta :title => "Resultados de la búsqueda '#{q}' - lospresus.de",
:description => "Resultados de la búsqueda '#{q}' en lospresus.de",
:keywords => "presupuestos, ayuntamientos, gastos, ingresos, subvenciones, municipios, municipal, dinero público, gasto público"

end
end
4 changes: 2 additions & 2 deletions app/models/municipio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def demographics_for(year)
def budget_for(year)
presupuestos.for_year(year).first
end
def self.search(query)
Municipio.find(:all, :conditions => ['nombre LIKE ?', "%#{query}%"], :limit => 10)
def self.search(query, options)
Municipio.find(:all, options.merge(:conditions => ['nombre LIKE ?', "%#{query}%"]))
end

def to_param
Expand Down
6 changes: 3 additions & 3 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<form class="initial_search" action="/search">
<% form_tag(cities_by_query_path, {:method => :get, :class => "initial_search"}) do %>
<label for="city_search">Ver presus de...</label>
<input id="city_search" autofocus type='text' placeholder='Escribe un municipio...'/>
<input id="city_search" autofocus type='text' placeholder='Escribe un municipio...' name="q">
<button class="btn">Ver</button>
</form>
<% end %>
16 changes: 16 additions & 0 deletions app/views/municipios/cities_by_query.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% content_for :header_title do %>
LO QUE BUSCAS
<% end %>


<% unless @results.blank? %>
<ul>
<% for muni in @results %>
<li><%= link_to muni.nombre, city_card_path(muni) %>, (<%= muni.province_name %>)</li>
<% end %>
</ul>
<% else %>
<ul>
<li>No hay ningún municipio que encaje con tu búsqueda.</li>
</ul>
<% end %>
14 changes: 8 additions & 6 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<h1><span>Los presupuestos de </span> <%= yield :header_title %></h1>
<p>Las cosas claras y el chocolate espeso</p>
</div>

<div class="budget">
<label for="municipality_go">Ver presus de...</label>
<input id="city_search" autofocus type='text' placeholder='Tu municipio...'>
<button class="btn">Ver</button>
</div>

<% form_tag(cities_by_query_path, {:method => :get}) do %>
<div class="budget">
<label for="municipality_go">Ver presus de...</label>
<input id="city_search" autofocus type='text' placeholder='Tu municipio...' name="q">
<button class="btn">Ver</button>
</div>
<% end %>
</div>
<!-- /header -->
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

map.with_options(:controller => 'municipios') do |muni|
muni.city_search '/search', :action => 'search'
muni.cities_by_query '/municipios', :action => 'cities_by_query'
muni.city_card '/:id', :action => 'show'
muni.city_search_for_compare '/:id/search_for_compare', :action => 'search_for_compare'
muni.city_evolution '/:id/evolucion', :action => 'evolution'
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(document).ready(function () {

$('#budget_timeline').jcarousel({
// Configuration goes here
scroll: 3,
scroll: 6,
start: 1,
initCallback: budget_timeline_callback,
buttonNextHTML: null,
Expand Down

0 comments on commit 64764d3

Please sign in to comment.