Merge pull request #14 from bumi/form-partial

Add form update
This commit is contained in:
bumi 2020-04-15 15:32:23 +02:00 committed by GitHub
commit c0064934e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 15 deletions

View File

@ -25,6 +25,19 @@ class FormsController < ApplicationController
end end
end end
def edit
@form = current_user.forms.find_by!(token: params[:id])
end
def update
@form = current_user.forms.find_by!(token: params[:id])
if @form.update(form_params)
redirect_to form_url(@form)
else
render :edit
end
end
def form def form
@form = Form.find_by!(token: params[:id]) @form = Form.find_by!(token: params[:id])
end end

View File

@ -0,0 +1,15 @@
<%= form_for form, local: true do |f| %>
<div class="field">
<div class="control">
<%= f.text_field :title, class: 'input', placeholder: 'Title' %>
</div>
</div>
<div class="field">
<div class="control">
<%= f.text_field :thank_you_url, class: 'input', placeholder: 'Thank you url' %>
</div>
</div>
<div>
<%= f.submit class: 'button is-primary' %>
</div>
<% end %>

View File

@ -0,0 +1,14 @@
<div class="section">
<div class=" columns ">
<div class="column is-half is-offset-one-quarter">
<div class="box">
<div class="content has-text-centered">
<h1 class="has-text-weight-light">Update <%= @form.title %></h1>
<%= render 'form', form: @form %>
</div>
</div>
</div>
</div>
</div>

View File

@ -4,21 +4,9 @@
<div class="box"> <div class="box">
<div class="content has-text-centered"> <div class="content has-text-centered">
<h1 class="has-text-weight-light">Create a new form</h1> <h1 class="has-text-weight-light">Create a new form</h1>
<%= form_for @form do |f| %>
<div class="field"> <%= render 'form', form: @form %>
<div class="control">
<%= f.text_field :title, class: 'input', placeholder: 'Title' %>
</div>
</div>
<div class="field">
<div class="control">
<%= f.text_field :thank_you_url, class: 'input', placeholder: 'Thank you url' %>
</div>
</div><br>
<div>
<%= f.submit class: 'button is-primary' %>
<% end %>
</divdiv>
</div> </div>
</div> </div>
</div> </div>