Commit Graph

10 Commits

Author SHA1 Message Date
Javi Martín
a7e1b42b6c Use checkboxes and radio buttons on poll forms
Our original interface to vote in a poll had a few issues:

* Since there was no button to send the form, it wasn't clear that
  selecting an option would automatically store it in the database.
* The interface was almost identical for single-choice questions and
  multiple-choice questions, which made it hard to know which type of
  question we were answering.
* Adding other type of questions, like open answers, was hard since we
  would have to add a different submit button for each answer.

So we're now using radio buttons for single-choice questions and
checkboxes for multiple-choice questions, which are the native controls
designed for these purposes, and a button to send the whole form.

Since we don't have a database table for poll ballots like we have for
budget ballots, we're adding a new `Poll::WebVote` model to manage poll
ballots. We're using WebVote instead of Ballot or Vote because they
could be mistaken with other vote classes.

Note that browsers don't allow removing answers with radio buttons, so
once somebody has voted in a single-choice question, they can't remove
the vote unless they manually edit their HTML. This is the same behavior
we had before commit 7df0e9a96.

As mentioned in c2010f975, we're now adding the `ChangeByZero` rubocop
rule, since we've removed the test that used `and change`.
2025-08-14 13:06:37 +02:00
Javi Martín
60dbda600d Move resolve clauses to the main routes file
We're going to add some constraints in the routes file, and if we add a
`resolve` clause inside a constraints block, we get an error saying that
"The resolve method can't be used inside a routes scope block" when
starting the application.
2024-11-06 11:07:00 +01:00
Javi Martín
03f89c9ca2 Move action to create answers to AnswersController
It was confusing to have the action to create an answer in
`QuestionsController#answer` while the action to destroy it was
`AnswersController#destroy`.
2024-06-26 20:20:24 +02:00
Javi Martín
9fbd7eec8f Remove obsolete routes for poll questions
The routes for poll questions were accidentally deleted in commit
5bb831e959 when deleting the `:show` action, and restored in commit
9871503c5e. However, the deleted code was:

```
resources :questions, only: [:show], controller: 'polls/questions' (...)
```

While the restored code was:

```
resources :questions, controller: 'polls/questions' (...)
```

Meaning we forgot to add the `only: []` option when restoring the
routes.

We also forgot to remove the `before_action` code when deleting the
`:show` action, so we're removing it now.
2024-06-26 20:20:24 +02:00
Senén Rodero Rodríguez
7df0e9a961 Allow to remove poll answers 2022-10-18 11:04:40 +02:00
Javi Martín
ff93f5a591 Use "resolve" for polymorphic hierarchy paths
In the past, we couldn't use `polymorphic_path` in many places. For
instance, `polymorphic_path(budget, investment)` would return
`budget_budget_investment_path`, while in our routes we had defined
`budget_investment_path`.

With the `resolve` method, introduced in Rails 5.1, we can use symbols
to define we want it to use `investment` instead of `budget_investment`.
It also works with nested resources, so now we can write
`polymorphic_path(investment)`.

This makes the code for `resource_hierarchy_for` almost impossible to
understand. I reached this result after having a look at the internals
of the `resolve` method in order to get its results and then remove the
symbols we include.

Note using this method will not make admin routes compatible with
`polymorphic_path`. Quoting from the Rails documentation:

> This custom behavior only applies to simple polymorphic URLs where a
> single model instance is passed and not more complicated forms, e.g:
> [example showing admin routes won't work]

Also note that now the `admin_polymorphic_path` method will not work for
every model due to inconsistencies in our admin routes. For instance, we
define `groups` and `budget_investments`; we should either use the
`budget_` prefix in all places or remove it everywhere. Right now the
code only works for items with the prefix; it isn't a big deal because
we never call it with an item without the prefix.

Finally, for unknown reasons some routing tests fail if we use
`polymorphic_path`, so we need to redefine that method in those tests
and force the `only_path: true` option.
2020-06-15 11:54:05 +02:00
Javi Martín
af7c37634d Remove poll votation types
Unfortunately this feature wasn't properly reviewed and tested, and it
had many bugs, some of them critical and hard to fix, like validations
being skipped in concurrent requests.

So we're removing it before releasing version 1.1. We might add it back
in the future if we manage to solve the critical issues.

This commit reverts commit 836f9ba7.
2019-10-30 18:48:55 +01:00
lalo
c6e4b2480f Add public changes to create and vote Poll:Questions with votation type 2019-06-12 19:44:14 +02:00
Julian Herrero
8510624692 Use double quotes in config/routes 2019-03-15 10:29:07 +01:00
Angel Perez
1cd47da9d4 Split routes into small files for easier customization (#1852) 2018-01-09 15:49:01 -04:00