]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
fixed duplicate fields in the post form
authorAidan Cornelius-Bell <[email protected]>
Mon, 16 Sep 2024 08:34:17 +0000 (18:04 +0930)
committerAidan Cornelius-Bell <[email protected]>
Mon, 16 Sep 2024 08:34:17 +0000 (18:04 +0930)
app/controllers/posts_controller.rb
app/views/.DS_Store
app/views/posts/_form.html.erb

index 4b39f116f1ee115c9de41e69956eb445462a56d0..e9e295efc4d81b349f32cd1b68cbd66bdef33b58 100644 (file)
@@ -24,11 +24,18 @@ class PostsController < ApplicationController
   def create
     @post = Post.new(post_params)
     @post.slug = @post.title.parameterize if @post.title.present?
-
+    
+    puts "Raw params: #{params.inspect}"
+    puts "Post params: #{post_params.inspect}"
+    puts "Post content: #{@post.content.inspect}"
+    puts "Post type: #{@post.post_type}"
+  
     if @post.save
       redirect_to @post, notice: "Post was successfully created."
     else
-      render :new, status: :unprocessable_entity
+    puts "Post errors: #{@post.errors.full_messages}"
+    puts "Post object: #{@post.attributes}"
+    render :new, status: :unprocessable_entity
     end
   end
 
index 21c52c5c7010b3404f459a2a3cdc3a86d6e5d196..90d4b9ee8db02ac0564b1f3d69565a66a974b073 100644 (file)
Binary files a/app/views/.DS_Store and b/app/views/.DS_Store differ
index dc31e1becb48f56f34e17400fd0dac463021437b..3595cf332b50686c3e08e69cdada3bce938633ea 100644 (file)
@@ -1,4 +1,4 @@
-<%= form_with(model: post, local: true) do |form| %>
+<%= form_with(model: post, local: true, data: { debug: true }) do |form| %>
   <% if post.errors.any? %>
     <div id="error_explanation">
       <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>
@@ -25,9 +25,9 @@
     <%= form.datetime_local_field :published_at %>
   </div>
 
-  <div class="field dispatch-field">
+  <div class="field">
     <%= form.label :content %>
-    <%= form.text_area :content, class: 'markdown-editor', rows: 10 %>
+    <%= form.text_area :content, id: 'post_content' %>
   </div>
 
   <div class="field dispatch-field">
     <%= form.url_field :url, onblur: 'fetchTitle()' %>
   </div>
 
-  <div class="field bookmark-field" style="display: none;">
-    <%= form.label :content, "Comment" %>
-    <%= form.text_area :content, rows: 3, placeholder: "Enter your comment here" %>
-  </div>
-
   <div class="actions">
     <%= form.submit(class: "button") %>
   </div>
 <% end %>
 
 <script>
+var simpleMDE;
+
 function toggleFields() {
   var postType = document.getElementById('post_post_type').value;
   var dispatchFields = document.getElementsByClassName('dispatch-field');
@@ -63,23 +60,37 @@ function toggleFields() {
     Array.from(dispatchFields).forEach(field => field.style.display = 'none');
     Array.from(bookmarkFields).forEach(field => field.style.display = 'block');
   }
+}
 
-  // Reinitialize SimpleMDE for newly displayed fields
-  var elements = document.querySelectorAll('.markdown-editor:not(.CodeMirror)')
-  elements.forEach(function(element) {
-    new SimpleMDE({ element: element })
-  })
+function initializeSimpleMDE() {
+  if (!simpleMDE) {
+    simpleMDE = new SimpleMDE({ element: document.getElementById('post_content') });
+    console.log("SimpleMDE initialized");
+  }
 }
 
 function fetchTitle() {
   var url = document.getElementById('post_url').value;
   if (url && document.getElementById('post_title').value === '') {
-    // You would implement the actual title fetching here, possibly using an AJAX call to a server endpoint
-    // For demonstration, we'll just set a placeholder title
     document.getElementById('post_title').value = 'Title for ' + url;
   }
 }
 
-// Initial toggle on page load
-document.addEventListener('DOMContentLoaded', toggleFields);
+document.addEventListener('DOMContentLoaded', function() {
+  console.log("DOM loaded");
+  toggleFields();
+  initializeSimpleMDE();
+});
+
+document.querySelector('form').addEventListener('submit', function(e) {
+  console.log("Form submission started");
+  console.log("Post type:", document.getElementById('post_post_type').value);
+  console.log("SimpleMDE content:", simpleMDE.value());
+
+  // Log all form data
+  var formData = new FormData(e.target);
+  for (var pair of formData.entries()) {
+    console.log(pair[0] + ': ' + pair[1]);
+  }
+});
 </script>
\ No newline at end of file