Skip to content

Commit

Permalink
search for compare
Browse files Browse the repository at this point in the history
  • Loading branch information
salicio committed Apr 18, 2010
1 parent 679cb15 commit a2c4eab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
14 changes: 13 additions & 1 deletion app/controllers/municipios_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MunicipiosController < ApplicationController
before_filter :find_muni, :only => [:show, :evolution, :compare]
before_filter :find_muni, :only => [:show, :evolution, :compare, :search_for_compare]
before_filter :year_context, :only => [:show, :compare]

def show
Expand All @@ -21,6 +21,18 @@ def search
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"

render :layout => false
end

def compare
@muni_b = Municipio.find_by_slug(params[:b_id])
meta :title => "Comparativa de los municipios de #{@muni.nombre} y #{@muni_b.nombre} - lospresus.de",
Expand Down
6 changes: 6 additions & 0 deletions app/views/municipios/search_for_compare.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[<% if [email protected]? -%>
<% for muni in @results -%>
{"name": "<%= escape_javascript(muni.nombre) -%>", "url": "<%= escape_javascript(city_compare_path(@muni,muni)) -%>"}
<%= "," unless muni == @results.last -%>
<% end -%>
<% end %>]
4 changes: 2 additions & 2 deletions app/views/municipios/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
</div>

<p class="comparison">
<label for="city_search">Comparar los presus de <strong><%= @muni.nombre %></strong> con los de:</label>
<input type='text' id="city_search" placeholder="Tu municipio..." autofocus>
<label for="city_compare_search">Comparar los presus de <strong><%= @muni.nombre %></strong> con los de:</label>
<input type='text' id="city_compare_search" placeholder="Tu municipio..." rel="<%= @muni.slug %>">
<button class="btn">Comparar</button>
</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
map.with_options(:controller => 'municipios') do |muni|
muni.city_search '/search', :action => 'search'
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'
muni.city_compare '/:id/y/:b_id', :action => 'compare'
muni.city_card_by_year '/:id/:year', :action => 'show'
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(document).ready(function () {
location.href = item.url;
});

$('#city_compare_search').autocomplete("/search", {
$('#city_compare_search').autocomplete($('#city_compare_search').attr('rel')+"/search_for_compare", {
dataType: "json",
parse: function(data) {
return $.map(data, function(row) {
Expand Down

0 comments on commit a2c4eab

Please sign in to comment.