Skip to content

Commit

Permalink
Fix form url
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Nov 5, 2024
1 parent 625a379 commit c25374b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/hotsheet/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def update # rubocop:disable Metrics/AbcSize
errors: record.errors.full_messages.join(", "))
end

redirect_to hotsheet_model_path(model)
redirect_to "#{root_path}#{model.table_name}"
end

private
Expand All @@ -33,7 +33,7 @@ def broadcast_params
end

def model_params
params.require(model.name.underscore.to_sym).permit(*model.editable_attributes)
params.require(model.name.underscore).permit(*model.editable_attributes)
end

def model
Expand Down
4 changes: 0 additions & 4 deletions app/helpers/hotsheet/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
module Hotsheet
module ApplicationHelper
include Pagy::Frontend

def hotsheet_model_path(model)
"#{root_path}#{model.table_name}"
end
end
end
6 changes: 3 additions & 3 deletions app/views/hotsheet/pages/_editable_attribute.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%# locals: (attribute:, record:) %>
<%# locals: (attribute:, model:, record:) %>

<%= turbo_frame_tag "#{dom_id record}-#{attribute}" do %>
<div data-controller="editable-attribute"
data-editable-attribute-broadcast-url-value="<%= broadcast_edit_intent_path %>"
data-editable-attribute-resource-name-value="<%= record.class.name.downcase %>"
data-editable-attribute-resource-name-value="<%= model.table_name %>"
data-editable-attribute-resource-id-value="<%= record.id %>">
<div class="readonly-attribute"
data-editable-attribute-target="readonlyAttribute"
Expand All @@ -12,7 +12,7 @@
</div>

<div data-editable-attribute-target="attributeForm" style="display:none">
<%= form_for record do |f| %>
<%= form_for record, url: "#{root_path}#{model.table_name}/#{record.id}" do |f| %>
<%= f.text_field attribute, class: "editable-input", data: {
editable_attribute_target: "attributeFormInput",
action: "keydown.enter->editable-attribute#submitForm blur->editable-attribute#submitForm"
Expand Down
4 changes: 2 additions & 2 deletions app/views/hotsheet/pages/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h1>Hotsheet</h1>
<p>Welcome to the hottest sheet around. Select a model from the sidebar to view the spreadsheet.</p>
<% else %>
<h1><%= @model %></h1>
<h1><%= @model.model_name.human %></h1>
<table>
<thead>
<tr>
Expand All @@ -16,7 +16,7 @@
<tr>
<% @model.editable_attributes.each do |attribute| %>
<td>
<%= render "editable_attribute", record: record, attribute: attribute %>
<%= render "editable_attribute", model: @model, record: record, attribute: attribute %>
</td>
<% end %>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/hotsheet/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<nav>
<ul>
<% Hotsheet.models.each do |model| %>
<%= link_to model.model_name.human, hotsheet_model_path(model) %>
<%= link_to model.model_name.human, "#{root_path}#{model.table_name}" %>
<% end %>
</ul>
</nav>
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/hotsheet/editable_attributes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

Rails.application.config.after_initialize do # rubocop:disable Metrics/BlockLength
# Only run this initializer when running the Rails server
next unless defined? Rails::Server

Hotsheet.configuration.models.each_key do |model| # rubocop:disable Metrics/BlockLength
model.constantize.class_eval do
class << self
Expand Down

0 comments on commit c25374b

Please sign in to comment.