Simplify new question form
In this form, the only case where `poll` might be present without `question.poll` being present to is going to be the `new` action. We can assign the poll in the `new` action and get rid of the `poll` variable in the form.
This commit is contained in:
@@ -8,9 +8,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12">
|
<div class="small-12">
|
||||||
<% if poll.present? %>
|
<% if question.poll.present? %>
|
||||||
<%= f.hidden_field :poll_id, value: poll.id %>
|
|
||||||
<% elsif question.poll.present? %>
|
|
||||||
<%= f.hidden_field :poll_id, value: question.poll.id %>
|
<%= f.hidden_field :poll_id, value: question.poll.id %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="small-12 medium-6 large-4 column">
|
<div class="small-12 medium-6 large-4 column">
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
class Admin::Poll::Questions::FormComponent < ApplicationComponent
|
class Admin::Poll::Questions::FormComponent < ApplicationComponent
|
||||||
include TranslatableFormHelper
|
include TranslatableFormHelper
|
||||||
include GlobalizeHelper
|
include GlobalizeHelper
|
||||||
attr_reader :poll, :question, :url
|
attr_reader :question, :url
|
||||||
|
|
||||||
def initialize(poll, question, url:)
|
def initialize(question, url:)
|
||||||
@poll = poll
|
|
||||||
@question = question
|
@question = question
|
||||||
@url = url
|
@url = url
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
|||||||
@polls = Poll.all
|
@polls = Poll.all
|
||||||
proposal = Proposal.find(params[:proposal_id]) if params[:proposal_id].present?
|
proposal = Proposal.find(params[:proposal_id]) if params[:proposal_id].present?
|
||||||
@question.copy_attributes_from_proposal(proposal)
|
@question.copy_attributes_from_proposal(proposal)
|
||||||
|
@question.poll = @poll
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<%= render Admin::Poll::Questions::FormComponent.new(@poll, @question, url: form_url) %>
|
<%= render Admin::Poll::Questions::FormComponent.new(@question, url: form_url) %>
|
||||||
|
|||||||
Reference in New Issue
Block a user