Skip to content

Commit

Permalink
* Renamed finishDate to finish_date
Browse files Browse the repository at this point in the history
 * using scope and sadded search
  • Loading branch information
wolas committed Apr 16, 2012
1 parent 2841a04 commit 1cf2ebc
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 13 deletions.
7 changes: 6 additions & 1 deletion app/controllers/events_controller.rb
Expand Up @@ -10,6 +10,11 @@ class EventsController < ApplicationController
after_filter :create_micropost, :only=>[:update]


def search
@events = Event.where((["CAST(title as varchar(255)) LIKE ?", "%#{params[:query]}%"]))
@events = @events.start_between(params[:start_date], params[:end_date])
end

# Filters events by category
def category
@category = Category.find(params[:category])
Expand All @@ -21,7 +26,7 @@ def category
def index
@events = Event.paginate(:page => params[:page])
#@events = Event.paginate(:page => params[:page], :order=> 'startDate ASC')
#@events = Event.where('finishDate >= ?', Time.now).order('startDate ASC').paginate(:page => params[:page])
#@events = Event.where('finish_date >= ?', Time.now).order('startDate ASC').paginate(:page => params[:page])
end


Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -83,7 +83,7 @@ def destroy
# Displays the reminders of a user
def reminders
@events = @user.events.where('finish_date >= ?', Time.now).paginate(:page => params[:page])
#@events = @even.find(:all, :conditions=> ['finishDate >= ?', Time.now])
#@events = @even.find(:all, :conditions=> ['finish_date >= ?', Time.now])
#@events = @user.events.paginate(:page =>params[:page])
end

Expand Down
7 changes: 5 additions & 2 deletions app/models/event.rb
Expand Up @@ -19,9 +19,12 @@ class Event < ActiveRecord::Base
# :path => "for/example/:id/:style.:extension",
# :url => ":s3_eu_url"

validates_datetime :finishDate, :after => :startDate
validates_datetime :finishDate, :on_or_after => lambda { Date.current }
validates_datetime :finish_date, :after => :startDate
validates_datetime :finish_date, :on_or_after => lambda { Date.current }
validates :title, :town, :description, presence: true

scope :start_between, lambda{|from, to| where ["start_date BETWEEN ? and ?", from.to_date - 1, to.to_date + 1] }

self.per_page = 10

# Sets Google maps coordenates
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/events/_form.html.haml
Expand Up @@ -24,9 +24,9 @@
%br
= f.datetime_select :startDate
.field
= f.label :finishDate
= f.label :finish_date
%br
= f.datetime_select :finishDate
= f.datetime_select :finish_date
.field
= f.label :place
%br
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/events/show.html.haml
Expand Up @@ -10,7 +10,7 @@
= l @event.startDate, :format => :long
%p
%b Finishes:
= l @event.finishDate, :format => :long
= l @event.finish_date, :format => :long
%p
%b Place:
= @event.place
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_form.html.haml
Expand Up @@ -26,7 +26,7 @@
.field
= f.label t :event_finish_date
%br
= f.datetime_select :finishDate
= f.datetime_select :finish_date
.field
= f.label t :event_place
%br
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/resubmit.html.haml
Expand Up @@ -36,7 +36,7 @@
.field
= f.label t :event_finish_date
%br
= f.datetime_select(:finishDate, :value => @old_event.finishDate)
= f.datetime_select(:finish_date, :value => @old_event.finish_date)
.field
= f.label t :event_place
%br
Expand Down
22 changes: 22 additions & 0 deletions app/views/events/search.html.haml
@@ -0,0 +1,22 @@
-@events.each do |event|
#block
#block_pic
= image_tag(event.pic.url(:medium), class: 'event_block_image', :alt =>'Event Picture')

#block_details
.event_title.capital
%b
=event.title
%div
%d
=l event.startDate, :format=> :block
%d.event_town
=event.place
%d.capital
=event.town
%p
%small
=truncate(strip_tags(event.description), length:320)
#block_info
.rotate_text
=link_to 'INFO', event
2 changes: 1 addition & 1 deletion app/views/events/show.html.haml
Expand Up @@ -13,7 +13,7 @@
%p
%b
= t :event_display_finish_date
= l @event.finishDate, :format => :long
= l @event.finish_date, :format => :long
%p
%b
= t :event_place
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/application.html.haml
Expand Up @@ -110,7 +110,7 @@

#left_bar

-if @leftbar_switch == true
- if @leftbar_switch
.left_bar_title.capital
=@lb_title
- @events_leftbar.each do |event|
Expand All @@ -128,6 +128,10 @@
= yield
#right
#search_box.shadow
= form_tag search_path do
= text_field_tag :query

= submit_tag "GO"



Expand Down
4 changes: 2 additions & 2 deletions app/views/users/events.html.haml
Expand Up @@ -9,7 +9,7 @@
- @events.each do |event|
#user_block
#user_block_pic
=pic = image_tag(event.pic.url(:medium), class: 'user_event_block_image', :alt =>'Event Picture')
= image_tag(event.pic.url(:medium), class: 'user_event_block_image', :alt =>'Event Picture')
#user_block_details{:style=>"width:53%;"}
.user_event_title.capital
%b
Expand All @@ -27,7 +27,7 @@
%small
=link_to I18n.t(:translation_pending), translation
#user_block_info
- if !event.cancelled && event.finishDate >= Time.now
- if !event.cancelled && event.finish_date >= Time.now
%div.rotate_div{:style=>"font-size:95%; background-color:8c8c8c;"}
.rotate_text.capital.line_height
=link_to I18n.t(:edit), edit_event_path(event)
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
@@ -1,5 +1,8 @@
Quasi::Application.routes.draw do


match "search" => "events#search", :as => "search"

# Defines all the routes under the language locale
scope "(:locale)", :locale => /es|eu|fr|en/ do
resources :followings
Expand Down

0 comments on commit 1cf2ebc

Please sign in to comment.