Skip to content

Commit

Permalink
Set the excuse msg as lang hash
Browse files Browse the repository at this point in the history
  • Loading branch information
aviscasillas committed Nov 9, 2013
1 parent c189cd8 commit 4cffc27
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/excuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ def index
end

def rnd
@excuse = Excuse.find_rnd
@msg = Excuse.find_rnd.msg['es']
end
end
7 changes: 4 additions & 3 deletions app/models/excuse.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class Excuse
include Mongoid::Document
field :lang, type: Symbol, default: :es
field :description, type: String

# Hash like { lang => msg }
field :msg, type: Hash

def self.find_rnd
where(lang: :es).sample
all.sample
end
end
2 changes: 1 addition & 1 deletion app/views/excuses/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- @excuses.each do |excuse|
p = excuse.description
p = excuse.msg
5 changes: 1 addition & 4 deletions app/views/excuses/rnd.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#main-excuse
- if @excuse
= @excuse.description
- else
No excuses available
= @msg || 'No excuses available'
6 changes: 3 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Excuse.all.each do |e|
e.remove
end
Excuse.create(description: 'Hoy hace mucha humedad')
Excuse.create(description: 'Esta roca se desace mucho')
Excuse.create(description: 'Si fuera un poco mas alto...')
Excuse.create(msg: { es: 'Hoy hace mucha humedad' } )
Excuse.create(msg: { es: 'Esta roca se desace mucho' } )
Excuse.create(msg: { es: 'Si fuera un poco mas alto...' } )

0 comments on commit 4cffc27

Please sign in to comment.