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
-<%= 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>
<%= 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');
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