diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 190be589..fc3e3bd5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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! diff --git a/app/controllers/members/votes_controller.rb b/app/controllers/members/votes_controller.rb index 60495121..00cfea94 100644 --- a/app/controllers/members/votes_controller.rb +++ b/app/controllers/members/votes_controller.rb @@ -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) @@ -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 diff --git a/app/models/vote.rb b/app/models/vote.rb index ffb316f8..24788ee7 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -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} @@ -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 diff --git a/app/views/members/applications/show.html.haml b/app/views/members/applications/show.html.haml index ac31e337..5e386572 100644 --- a/app/views/members/applications/show.html.haml +++ b/app/views/members/applications/show.html.haml @@ -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 } diff --git a/db/migrate/20240207000000_add_vote_value_to_vote.rb b/db/migrate/20240207000000_add_vote_value_to_vote.rb new file mode 100644 index 00000000..bc628e7d --- /dev/null +++ b/db/migrate/20240207000000_add_vote_value_to_vote.rb @@ -0,0 +1,5 @@ +class AddVoteValueToVote < ActiveRecord::Migration[6.0] + def change + add_column :votes, :vote_value, :string + end +end