Skip to content

Commit

Permalink
Small style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
badosu committed Apr 25, 2015
1 parent 6c75c98 commit cbeb6c8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
20 changes: 20 additions & 0 deletions config/warden.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'warden'

Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User[id] }

Warden::Strategies.add(:password) do
def valid?
params["email"] || params["password"]
end

def authenticate!
user = User.first(email: params["email"])

if user && user.authenticate(params["password"])
success! user
else
fail! "Could not log in"
end
end
end
5 changes: 5 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
unless env.production?
DB[:communities].truncate
end


Community.create name: "New Community",
description: "This is a nice community"
30 changes: 16 additions & 14 deletions routes/communities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Yogurt
end

r.post do
attributes = %w[name description private]
@community = Community.new.set_fields(r.params, attributes)
fields = %w[name description private]
@community = Community.new.set_fields(r.params, fields)

if @community.save
r.redirect '/communities'
Expand All @@ -24,28 +24,30 @@ class Yogurt
r.get 'new' do
@community = Community.new

r.get { :new }
:new
end

r.on ':id' do |id|
r.on :id do |id|
@community = Community.with_pk!(id.to_i)

r.get('edit') { :edit }

r.put do
attributes = %w[name description private]
r.is do
r.put do
fields = %w[name description private]

if @community.update_fields(r.params, attributes)
r.redirect '/communities'
else
:edit
if @community.update_fields(r.params, fields)
r.redirect '/communities'
else
:edit
end
end
end

r.delete do
@community.delete
r.delete do
@community.delete

r.redirect '/communities'
r.redirect '/communities'
end
end
end
end
Expand Down

0 comments on commit cbeb6c8

Please sign in to comment.