Les colonnes booléennes sont bien gérées par rails, mais il faut les utiliser avec ?

This commit is contained in:
echarp 2014-07-01 23:00:05 +02:00
parent 12c621df2b
commit 8afe5848da
6 changed files with 8 additions and 15 deletions

View File

@ -4,7 +4,7 @@ class EventsController < ApplicationController
before_filter :set_mailer_host before_filter :set_mailer_host
def index def index
@events = Event.all_moderated @events = Event.moderated
if params[:region] && params[:region].present? && params[:region] != 'all' if params[:region] && params[:region].present? && params[:region] != 'all'
@events = @events.region params[:region] @events = @events.region params[:region]
end end
@ -108,7 +108,7 @@ class EventsController < ApplicationController
if params[:secret].present? if params[:secret].present?
@event = Event.where secret: params[:secret] @event = Event.where secret: params[:secret]
else else
@event = Event.all_moderated @event = Event.moderated
end end
@event = @event.find params[:id] @event = @event.find params[:id]
end end

View File

@ -1,6 +1,3 @@
# TODO migrate moderated column to a SQL bool type
# TODO migrate locality column to a SQL bool type
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
extend SimpleCalendar extend SimpleCalendar
@ -14,7 +11,7 @@ class Event < ActiveRecord::Base
validates :submitter, email: true validates :submitter, email: true
scope :all_moderated, -> { where moderated: 1 } scope :moderated, -> { where moderated: true }
scope :past, -> { where('end_time < now()').order(start_time: :desc) } scope :past, -> { where('end_time < now()').order(start_time: :desc) }
scope :future, -> { where('end_time >= now()').order(start_time: :asc) } scope :future, -> { where('end_time >= now()').order(start_time: :asc) }
scope :future_30, -> { scope :future_30, -> {
@ -30,7 +27,7 @@ class Event < ActiveRecord::Base
start_date.beginning_of_week, start_date.beginning_of_week,
start_date.next_month.end_of_week start_date.next_month.end_of_week
} }
scope :region, -> region { where 'region = ? or locality = 1', region } scope :region, -> region { where 'region = ? or locality', region }
scope :tag, -> tag { where 'tags like ?', "%#{tag}%" } scope :tag, -> tag { where 'tags like ?', "%#{tag}%" }
@ -52,8 +49,4 @@ class Event < ActiveRecord::Base
def same_day? def same_day?
start_time.to_date == end_time.to_date start_time.to_date == end_time.to_date
end end
def is_moderated?
moderated == 1
end
end end

View File

@ -3,7 +3,7 @@
=t '.title' =t '.title'
.box .box
- if @event.is_moderated? - if @event.moderated?
%h3=t '.already_moderated' %h3=t '.already_moderated'
= form_for @event, method: :delete do |f| = form_for @event, method: :delete do |f|

View File

@ -2,7 +2,7 @@
>>> >>>
=t '.preview' =t '.preview'
- if @event.is_moderated? - if @event.moderated?
.box .box
%h3=t '.warning' %h3=t '.warning'

View File

@ -3,7 +3,7 @@
>>> >>>
=t '.preview' =t '.preview'
- if @moderation.is_moderated? - if @moderation.moderated?
.box .box
%h3=t '.warning' %h3=t '.warning'

View File

@ -4,7 +4,7 @@
=t '.title' =t '.title'
.box .box
- if @event.locality == 1 - if @event.locality?
%h2.warning=t '.warning' %h2.warning=t '.warning'
%h2=t '.question' %h2=t '.question'