Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP add Not Sure to voting options #801

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def vote(application_id_param, vote_value)
vote.application ||= application
vote.user ||= current_user
vote.value = vote_value
# vote.vote_value = vote_value # TODO Linda

vote.save!

Expand Down
8 changes: 8 additions & 0 deletions app/controllers/members/votes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Members::VotesController < Members::MembersController
def create
vote(application_id_param, !!params[:vote_yes])
# vote(application_id_param, parsed_vote_value) # TODO Linda

application = Application.find(application_id_param)
redirect_to members_application_path(application)
Expand All @@ -20,6 +21,13 @@ def destroy

private

def parsed_vote_value
return Vote::YES if params[:vote_yes] == true
return Vote::NO if params[:vote_no] == true
return Vote::NOT_SURE if params[:vote_not_sure] == true
raise "Invalid vote value #{params.inspect}"
end

def application_id_param
params.require(:vote).require(:application_id)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/vote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Vote < ApplicationRecord
validates :application_id, presence: true

validates :value, inclusion: {in: [true, false]}
enum vote_value: %w(yes no not_sure).mirror_hash

validates :user_id, uniqueness: {scope: :application_id}

Expand Down Expand Up @@ -43,6 +44,7 @@ def no?
#
# id :integer not null, primary key
# value :boolean not null
# vote_role :string
# created_at :datetime
# updated_at :datetime
# application_id :integer not null
Expand Down
3 changes: 3 additions & 0 deletions app/views/members/applications/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
= f.hidden_field :application_id, value: @application.id
= f.submit 'Yes', name: 'vote_yes', disabled: vote && vote.value
= f.submit 'No', name: 'vote_no', disabled: vote && !vote.value
-# = f.submit 'Yes', name: 'vote_yes', disabled: vote&.yes?
-# = f.submit 'No', name: 'vote_no', disabled: vote&.no?
-# = f.submit 'Not Sure', name: 'vote_not_sure', disabled: vote&.not_sure?

- if current_user.voted_on?(@application)
#{ link_to 'Remove your vote', members_vote_path, method: :delete }
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240207000000_add_vote_value_to_vote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVoteValueToVote < ActiveRecord::Migration[6.0]
def change
add_column :votes, :vote_value, :string
end
end
Loading