From f12238fbd4d591994443027246cea77f0dea7648 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Tue, 14 Apr 2020 14:25:38 +0200 Subject: [PATCH] Add form update --- app/controllers/forms_controller.rb | 13 +++++++++++++ app/views/forms/_form.html.erb | 15 +++++++++++++++ app/views/forms/edit.html.erb | 14 ++++++++++++++ app/views/forms/new.html.erb | 18 +++--------------- 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 app/views/forms/_form.html.erb create mode 100644 app/views/forms/edit.html.erb diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index 92c2ece..4b0ac01 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -25,6 +25,19 @@ class FormsController < ApplicationController 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 @form = Form.find_by!(token: params[:id]) end diff --git a/app/views/forms/_form.html.erb b/app/views/forms/_form.html.erb new file mode 100644 index 0000000..c03993b --- /dev/null +++ b/app/views/forms/_form.html.erb @@ -0,0 +1,15 @@ +<%= form_for form, local: true do |f| %> +
+
+ <%= f.text_field :title, class: 'input', placeholder: 'Title' %> +
+
+
+
+ <%= f.text_field :thank_you_url, class: 'input', placeholder: 'Thank you url' %> +
+
+
+ <%= f.submit class: 'button is-primary' %> +
+<% end %> diff --git a/app/views/forms/edit.html.erb b/app/views/forms/edit.html.erb new file mode 100644 index 0000000..4e04451 --- /dev/null +++ b/app/views/forms/edit.html.erb @@ -0,0 +1,14 @@ +
+
+
+
+
+

Update <%= @form.title %>

+ + <%= render 'form', form: @form %> + +
+
+
+
+
diff --git a/app/views/forms/new.html.erb b/app/views/forms/new.html.erb index 1229375..ac8f1aa 100644 --- a/app/views/forms/new.html.erb +++ b/app/views/forms/new.html.erb @@ -4,21 +4,9 @@

Create a new form

- <%= form_for @form do |f| %> -
-
- <%= f.text_field :title, class: 'input', placeholder: 'Title' %> -
-
-
-
- <%= f.text_field :thank_you_url, class: 'input', placeholder: 'Thank you url' %> -
-

-
- <%= f.submit class: 'button is-primary' %> - <% end %> - + + <%= render 'form', form: @form %> +