Adapt 'show' view for open questions without options
- Prevent creating options for open questions - Skip rendering the options table when none exist
This commit is contained in:
@@ -101,7 +101,7 @@ module Abilities
|
||||
end
|
||||
can [:read, :order_options], Poll::Question::Option
|
||||
can [:create, :update, :destroy], Poll::Question::Option do |option|
|
||||
can?(:update, option.question)
|
||||
can?(:update, option.question) && option.question.accepts_options?
|
||||
end
|
||||
can :read, Poll::Question::Option::Video
|
||||
can [:create, :update, :destroy], Poll::Question::Option::Video do |video|
|
||||
|
||||
@@ -61,6 +61,10 @@ class Poll::Question < ApplicationRecord
|
||||
votation_type.nil? || votation_type.unique?
|
||||
end
|
||||
|
||||
def accepts_options?
|
||||
votation_type.nil? || votation_type.accepts_options?
|
||||
end
|
||||
|
||||
def max_votes
|
||||
if multiple?
|
||||
votation_type.max_votes
|
||||
|
||||
@@ -9,6 +9,10 @@ class VotationType < ApplicationRecord
|
||||
validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }}
|
||||
validates :max_votes, presence: true, if: :max_votes_required?
|
||||
|
||||
def accepts_options?
|
||||
!open?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def max_votes_required?
|
||||
|
||||
Reference in New Issue
Block a user