Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
halfdan committed Jan 28, 2016
1 parent e02b7a8 commit 9fbc200
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/controllers/changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
if is_logged_in?
@badge = Badge.find params[:id]
@change = BadgeChange.new badge: @badge, user: current_user
@change.votes.build
render 'new'
else
redirect url(:static, :index)
Expand All @@ -27,9 +26,9 @@
end
end

put :accept, map: '/badges/:badge_id/change/:change_id/accept' do
put :accept, map: '/changes/:change_id/accept' do
end

put :reject, map: '/badges/:badge_id/change/:change_id/reject' do
put :reject, map: '/changes/:change_id/reject' do
end
end
28 changes: 28 additions & 0 deletions app/controllers/votes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Embadge::App.controllers :votes do

get :new, map: '/changes/:id/vote/new' do
@change = BadgeChange.find params[:id]
if is_logged_in?
@vote = Vote.new badge_change: @change, user: current_user
render 'new'
else
redirect url(:static, :index)
end
end

post :create, map: '/changes/:id/vote/create' do
if is_logged_in?
@vote = Vote.new(params[:vote])
@change = BadgeChange.find params[:id]
@vote.badge_change = @change
@vote.user = current_user

if @vote.save
redirect(url(:badges, :show, id: @change.badge.id))
else
flash.now[:error] = "Nope"
render 'votes/new'
end
end
end
end
4 changes: 0 additions & 4 deletions app/helpers/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ def current_user
@current_user ||= User.find_by_id(session[:current_user])
end

def reset_session

end

def is_logged_in?
return current_user.present?
end
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/votes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Helper methods defined here can be accessed in any controller or view in the application

module Embadge
class App
module VotesHelper
# def simple_helper_method
# ...
# end
end

helpers VotesHelper
end
end
7 changes: 7 additions & 0 deletions app/views/votes/_form.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= f.error_messages
%div.form-group
= f.label :comment
= f.text_area :comment, class: 'form-control'

%div.form-group
= f.submit "Submit", class: 'btn btn-default'
6 changes: 6 additions & 0 deletions app/views/votes/new.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%h2 Vote
= flash_tag(:error)
= form_for @vote, url(:votes, :create, id: @change.id), id: 'new_vote' do |f|
= partial 'votes/form', locals: {f: f}

%a{href: url(:badges, :show, id: @change.badge.id)} Back to badge

0 comments on commit 9fbc200

Please sign in to comment.