Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Búsqueda en ubuntufeeds y performance #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@

# Vim temporal viles
*.swp

#Ignore my local files changes
/config/database.yml
Gemfile
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'sqlite3'
end

group :development, :test do
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -275,6 +276,7 @@ DEPENDENCIES
rspec-rails
sass-rails (~> 3.2.3)
simple_form
sqlite3
therubyracer
twitter
uglifier (>= 1.0.3)
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
development:
host: localhost
adapter: postgresql
adapter: sqlite3
encoding: unicode
database: ubuntufeed_development
pool: 5
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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