From 8f45af851bad5c6a16c328dcdc6b95e7bce58858 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 7 May 2013 21:56:36 -0500 Subject: [PATCH] =?UTF-8?q?Se=20agrega=20b=C3=BAsqueda=20y=20se=20mejora?= =?UTF-8?q?=20el=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/posts_controller.rb | 13 ++++++++++++- app/views/layouts/application.html.haml | 3 +++ config/database.yml | 2 +- config/routes.rb | 2 ++ 7 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0cb7ae5..63df26b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ # Vim temporal viles *.swp + +#Ignore my local files changes +/config/database.yml +Gemfile \ No newline at end of file diff --git a/Gemfile b/Gemfile index ccf55e5..cb02a30 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ group :development do gem 'better_errors' gem 'binding_of_caller' gem 'meta_request' + gem 'sqlite3' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 3d3ec14..87d12ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -226,6 +226,7 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.7) terminal-table (1.4.5) therubyracer (0.11.3) libv8 (~> 3.11.8.12) @@ -275,6 +276,7 @@ DEPENDENCIES rspec-rails sass-rails (~> 3.2.3) simple_form + sqlite3 therubyracer twitter uglifier (>= 1.0.3) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 061bad6..03d133d 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,7 +1,7 @@ class PostsController < ApplicationController layout 'redirect', :only => [:post] def index - @posts = Post.order('pubdate DESC').page params[:page] + @posts = Post.includes(:blog).order('pubdate DESC').page params[:page] @number = params[:page] respond_to do |format| format.html # show.html.erb @@ -42,4 +42,15 @@ def post def populares @stats = Stat.order('clicks DESC').limit(50) end + + def busca_post + @posts = Post.includes(:blog).where("title like '%#{params[:txtBuscar]}%' or slug like '%#{params[:txtBuscar]}%'").page params[:page ] + respond_to do |format| + format.html { render "index" } + format.json { render :json => @posts.to_json( + :methods => [:date,:date_string], + :include => { :blog => { :only => :title } } + ) } + end + end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index f6c7fed..290644c 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -64,6 +64,9 @@ = paginate @posts -else =link_to "h", root_path + %li.buscar + %form{:action => "/busca", :method => "post", :target => "_top"} + %input{:type => "textbox", :name => "txtBuscar", :id => "txtBuscar", :placeholder => "buscar", :class =>"busqueda"} = yield %footer .contenedor diff --git a/config/database.yml b/config/database.yml index d3d5bfb..a9b214e 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,6 +1,6 @@ development: host: localhost - adapter: postgresql + adapter: sqlite3 encoding: unicode database: ubuntufeed_development pool: 5 diff --git a/config/routes.rb b/config/routes.rb index 765fa35..cddf268 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,4 +28,6 @@ post '/encuesta', :to => 'posts#create_encuesta', :as => 'create_encuesta' match '*path' => redirect('/') unless Rails.env.development? + + match '/busca' => 'posts#busca_post' end