Build templates in views - ruby-on-rails

In grails I do this:
<form:windowEntrada domain="serverPool">
<form:entrada domain="serverLocation" bean="${serverPoolInstance}">
<form:textField label="serverPool.name" name="name" />
<form:select label="serverPool.server" name="server" list="${Servers.list()}"/>
</form:entrada>
</form:windowEntrada>
The tag "form:textField" render something like:
<div class='field-name'>
<div class="title"><label for="name">Name</label>(* required)</div>
<div class="fieldcontent"><input type="text" name="name" value="smtg"></div>
<div class="error">If thereis an error on this field, the message appears here</div>
</div>
The tag "form:windowEntrada" render something like:
<div class='container'>
<h1>My title here</h1>
<div class="content">${body()}</div>
</div>
The tag "form:entrada" render something like:
<form action ... >
<....> --> messages stuff
${body()}
<div class="action-buttons">
<input type="submit" name="lala">
<input type="submit" name="lala2">
</div>
</div>
How can I do i rails using erb as my view tecnology?
Thank you.

I Have found the answer here: pathfindersoftware.com/2008/07/pretty-blocks-in-rails-views
Here's an example applying the tutorial:
In ERB:
<%= widget("mytitle", {:class => "widget-table"}) do %>
test test test
<% end %>
in the helper:
def widget(title, options = {}, &block)
options[:params] = params
options[:controller_name] = controller.controller_name
body = capture &block
html = render "shared/form/widget", :body => body,
:title => title,
:options => options
return html
end
and the template _widget.html.erb:
<div class="widget <%= options[:class] unless options[:class].blank? %>">
<% unless title.blank? %>
<div class="widget-header">
<span class="icon-layers"></span>
<h3><%= title %></h3>
</div>
<% end %>
<div class="widget-content">
<%= body%>
</div>
</div>
tks

Related

Rails stimulus one form change for many urls and turbo frames

I am building a dashboard with multiple elements like charts, tables, simple fields with calculated values etc and I want to use Rails7 with stimulus.
In the past I used jQuery so I just created empty elements and then called several ajax requests in paralel to get data for every elements and populate it. So initial page load was super fast and then it loaded all necessary data. Dashboard had few dropdowns options to change data and when I loaded page I just sent defaults. Every dropdown change reloaded all data for all elements by filter used in dropdown.
How to do similar approach with stimulus?
When I use turbo form what I can do is submit form on page load, but it looks ugly (page initially loads and instantly reloads). And if I have many elements it gets slow because it first needs to finish all calculations.
this is my simple filter with 2 dropdowns
<%= form_with url: "", method: :get, data: { controller: "home", home_target: "form", turbo_frame: "home_dashboard", turbo_action: "advance" } do |form| %>
<div class="row">
<div class="d-sm-flex align-items-center mb-3">
<div class="col-lg-2" >
<%= form.select :city, options_for_select(City.all.pluck(:name,:id)), {include_blank: (t 'all')}, {class: 'form-select', data: {action: "input->home#search"}} %>
</div>
<div class="col-lg-2" >
<%= form.select :year, options_for_select(#years.reverse, (params[:year] || Date.today.year)), {selected: params[:year], include_blank:false}, {class: 'form-select', data: {action: "input->home#search"}} %>
</div>
</div>
</div>
<% end %>
and this is my home controller in stimulus which is simple
import { Controller } from "#hotwired/stimulus"
// Connects to data-controller="home"
export default class extends Controller {
connect() {
}
static targets = ["form"]
connect() {
this.formTarget.requestSubmit()
}
search() {
this.formTarget.requestSubmit()
}
}
my rails controller gets ugly big because I am calculating lot of fields dynamically and showing them in turbo frame tag...this is just a part of data I want to show so there should be much more
<%= turbo_frame_tag "home_dashboard" do %>
<div class="row">
<div class="col-xl-6">
<div class="card border-0 mb-3 overflow-hidden ">
<div class="card-body">
<div class="row">
<div class="col-xl-7 col-lg-8">
<div class="mb-3 fs-13px">
<b><%= (t 'invoices.invoiced').upcase %></b>
</div>
<div class="d-flex mb-1">
<% if #invoices_sumed.present? %>
<h2 class="mb-0"><span data-animation="number" data-value="<%= #invoices_sumed[0][1] %>"><%= #invoices_sumed[0][1] %></span> <%= #invoices_sumed[0][0] %></h2>
<% else %>
<h2 class="mb-0"><span data-animation="number" data-value="0">0</span> EUR</h2>
<% end %>
</div>
<div class="mb-3">
<i class="fa fa-caret-up"></i> <span data-animation="number" data-value="<%= #invoices_sumed_compare %>"><%= #invoices_sumed_compare %></span>% <%= t 'invoices.compared_previous_year' %>
</div>
<hr>
<div class="row text-truncate">
<div class="col-6">
<div class=""><%= t 'invoices.total' %></div>
<div class="fs-18px mb-5px fw-bold" data-animation="number" data-value="<%= #invoices.size %>"><%= #invoices.size %></div>
<div class="progress h-5px rounded-3 mb-5px">
<div class="progress-bar progress-bar-striped rounded-right " data-animation="width" data-value="<%= calc_year_ratio(#invoices.size,#invoices_total_size) %>%" style="width: <%= calc_year_ratio(#invoices.size,#invoices_total_size) %>%;"></div>
</div>
</div>
<div class="col-6">
<div class=""><%= t 'invoices.average' %> <small>(<%= (t 'invoices.median').to_s + ":" %> <strong><%= "#{#invoices_median_value.round(2)} #{#invoices_top_currency}" %></strong>)</small></div>
<div class="fs-18px mb-5px fw-bold"><span data-animation="number" data-value="<%= #invoices_avg_value.round(2) %>"><%= #invoices_avg_value.round(2) %></span> <%= #invoices_top_currency %></div>
<div class="progress h-5px rounded-3 mb-5px">
<div class="progress-bar progress-bar-striped rounded-right bg-orange" data-animation="width" data-value="<%= calc_median_total_ratio(#invoices_avg_value,#invoices_max_value) %>%" style="width: <%= calc_median_total_ratio(#invoices_avg_value,#invoices_max_value) %>%;"></div>
</div>
</div>
</div>
</div>
<div class="col-xl-5 col-lg-4 align-items-center d-flex justify-content-center">
<canvas
data-controller="chart"
data-chart-data-value='<%= #chart_total.to_json %>'
data-chart-options-value="<%= #chart_options.to_json %>"
></canvas>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4">
<div class="table-responsive">
<table id="contractors" class="table table-hover align-middle" style="width:100%;">
<thead></thead>
<tbody>
<% #contractors.each do |contractor| %>
<tr>
<td><%= contractor[0]%></td>
<td><%= contractor[2]%></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<% end %>
is there any way how to split this in multiple turbo frames with multiple urls to call with one form select change?

Rails - My 'create/new' method doesn't work

I've created a form so the user can add a new picture to the website catalog, but for some reasons it doesn't work. Once the form is filled out, I click on the 'Submit' button but nothing happens, I just stay on the same page (and I don't have any error message...).
I don't think the error comes from my Controller since nothing happens when I add the raise keyword in my Controller's 'create' method.
I'm sure this is an amateur mistake... but I can't see what it is. Thanks for your help!
picture.rb /
Picture model:
class Picture < ApplicationRecord
validates :name, presence: true
has_many_attached :photo
end
new.html.erb /
Here is my form :
<%= form_for(#picture) do |f| %>
<div class="form-group">
<%= f.label :name, "Please indicate the name" %>
<%= f.text_field :name, class:"form-control", placeholder:"(mandatory field)" %>
</div>
<div class="form-group">
<%= f.label :description, "Add a description" %>
<%= f.text_area :description, class:"form-control" %>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<%= f.label :category, "Add a category" %>
<%= f.text_field :category, class:"form-control" %>
</div>
<div class="col">
<%= f.label :price, "Indicate the price (when applicable)" %>
<%= f.number_field :price, class:"form-control", placeholder:"0,00$ CAD" %>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<p>Where do you want to add this item?</p>
<div>
<%= f.check_box :is_home_item %>
<%= f.label :is_home_item, "Homepage" %>
</div>
<div>
<%= f.check_box :is_portfolio_item %>
<%= f.label :is_portfolio_item, "Work" %>
</div>
<div>
<%= f.check_box :is_sketchbook_item %>
<%= f.label :is_sketchbook_item, "Sketchbook" %>
</div>
<div>
<%= f.check_box :is_shopping_item %>
<%= f.label :is_shopping_item, "Shopping" %>
</div>
</div>
<div class="col">
<div class="form-group">
<%= f.label :photo, "Select your picture" %>
<%= f.file_field :photo, class:"form-control-file" %>
</div>
</div>
</div>
</div>
<div class="form-group">
<%= f.submit class:"btn btn-lg btn-primary" %>
</div>
<% end %>
pictures_controller.rb /
class PicturesController < ApplicationController
def new
#picture = Picture.new
end
def create
#picture = Picture.new(picture_params)
if #picture.save
redirect_to root_path(#picture), notice: "Picture was successfully created"
else
render :new
end
end
private
def picture_params
params.require(:picture).permit(:name, :description, :category, :price, :is_home_item, :is_portfolio_item, :is_sketchbook_item, :is_shopping_item, :photo)
end
end
And here is the text I got on my local server console
Here is the HTML output of my form :
<form>
<input type="hidden" name="authenticity_token" value="7MxWbzbltjXcAx2dvgRwIu07WMpyjPQji6LI6ELifMZODLJyMBucNApnPRk8vsjshSEjyMMenDUfvDw6pN+/4Q==">
<div class="form-group">
<label for="picture_name">Indicate the name</label>
<input class="form-control" placeholder="(mandatory field)" type="text" name="picture[name]" id="picture_name">
</div>
<div class="form-group">
<label for="picture_description">Add a description</label>
<textarea class="form-control" name="picture[description]" id="picture_description"></textarea>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<label for="picture_category">Add a category</label>
<input class="form-control" type="text" name="picture[category]" id="picture_category">
</div>
<div class="col">
<label for="picture_price">Indicate the price (when applicable)</label>
<input class="form-control" placeholder="0,00$ CAD" type="number" name="picture[price]" id="picture_price">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<p>Where do you want to add your picture?</p>
<div>
<input name="picture[is_home_item]" type="hidden" value="0"><input type="checkbox" value="1" name="picture[is_home_item]" id="picture_is_home_item">
<label for="picture_is_home_item">Homepage</label>
</div>
<div>
<input name="picture[is_portfolio_item]" type="hidden" value="0"><input type="checkbox" value="1" name="picture[is_portfolio_item]" id="picture_is_portfolio_item">
<label for="picture_is_portfolio_item">Work</label>
</div>
<div>
<input name="picture[is_sketchbook_item]" type="hidden" value="0"><input type="checkbox" value="1" name="picture[is_sketchbook_item]" id="picture_is_sketchbook_item">
<label for="picture_is_sketchbook_item">Sketchbook</label>
</div>
<div>
<input name="picture[is_shopping_item]" type="hidden" value="0"><input type="checkbox" value="1" name="picture[is_shopping_item]" id="picture_is_shopping_item">
<label for="picture_is_shopping_item">Shopping</label>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="picture_photo">Select your picture</label>
<input class="form-control-file" type="file" name="picture[photo]" id="picture_photo">
</div>
</div>
</div>
</div>
<div class="form-group">
<input type="submit" name="commit" value="Create Picture" class="btn btn-lg btn-primary" data-disable-with="Create Picture">
</div>
My routes :
Rails.application.routes.draw do
devise_for :users
# Pages routes
root to: 'pages#home'
get 'about', to: 'pages#about'
get 'portfolio', to: 'pages#portfolio'
get 'sketchbook', to: 'pages#sketchbook'
get 'shopping', to: 'pages#shopping'
# Pictures routes
resources :pictures
end
And these are my routes in the Terminal
Not quite sure why this is happening, but form_for is deprecated, so you should replace it with form_with.
You can use a model, such as your #picture with form_with as described in the docs.
<%= form_with(model: #picture) do |form| %>
# fields
<% end %>
This should create a form DOM object that looks like this:
<form action="/pictures" method="post" accept-charset="UTF-8" >
<input name="authenticity_token" type="hidden" value="..." />
...
</form>
If for some reason it doesn't, you can always pass a method: :post in the form_with (ie. <%= form_with(model: #picture, method: :post) do |form| %>).
Currently, you have got has_many_attached with a singular photo. That does not seem to be the right syntax. Have you tried changing to has_many_attached :photos and modifying the picture_params to have photos passed as an array photos: []?
Or if you wanted to attach one photo, then you should try changing to has_one_attached :photo in the Picture model.

Not able to view the drop down options in rails UI

Below code snippet is a case add form where it shows the select tag in UI but if it is clicked on its arrow button nothing is viewed, in-browser console it shows all the select options.
<div id="addCaseForm" style="display:none">
<%= form_tag("#{#view.addUrl}", method: "post") do %>
<div class="row padlef">
<div class="col-sm-8">
<div class="form-group">
<%= label_tag("Case Title:") %>
<%= text_field_tag(:name) %>
<div class="help-block with-errors"></div>
<div>
<div>
</div>
<div class="padlef">
<div class="form-group">
<div class="col-sm-3 f-n32 p7-lr">
<%= label_tag("Assign To") %>
<%= select_tag 'userId', option_for_select_assignee %>
<div class="help-block with-errors"></div>
</div>
<div class="col-md-3 f-n32 p7-lr">
<%= label_tag("Priority")%>
<%= select_tag 'priority', option_for_select_priority %>
<div class="help-block with-errors"></div>
</div>
<div class="col-md-2 f-n32 p7-lr">
<%= label_tag("Case Type") %>
<%= select_tag 'c_type', option_for_select_c_type %>
<div class="help-block with-errors"></div>
</div>
<div class="form-group margboth margbot col-md-12 clearfix">
<a class="btn btn-primary ftn16 hvr-shutter-out-horizontal cancelAddCase"><i class="fa fa-times-circle "></i> Cancel</a>
<button type="button" class="btn btn-primary submit ftn16 hvr-shutter-out-horizontal pull-left" ><i class="fa fa-plus-circle "></i> Add</button>
</div>
</div>
<div>
<% end %>
</div>
and the helper code is as follows
module CaseHelper
def option_for_select_priority
return([['Urgent','P0'],['P1','P1'],['P2','P2'],['P3','P3'],['P4','P4']])
end
def option_for_select_assignee
list = [['','Unassigned']]
#view.members.sort_by(&:show_name).each do |member|
list << ["#{member.id}", "#{member.show_name}"]
end
return(list)
end
def option_for_select_c_type
return ([['Issue','issue'],['Change Request','C-R']])
end
end
Not sure how you're able to view the correct HTML in developer tools, because this...
select_tag 'priority', option_for_select_priority
returns...
<select id="priority" name="priority">
[["Urgent", "P0"], ["P1", "P1"], ["P2", "P2"], ["P3", "P3"], ["P4", "P4"]]
</select>
So what you really want is to wrap the method option_for_select_priority inside the options_for_select call. Like this...
select_tag 'priority', options_for_select(option_for_select_priority)
which returns...
<select id="priority" name="priority">
<option value="P0">Urgent</option>
<option value="P1">P1</option>
<option value="P2">P2</option>
<option value="P3">P3</option>
<option value="P4">P4</option>
</select>

It does not redirect to the show method

historys_controller.rb
class Facturacion::HistorysController < Facturacion::AuthorizeController
#before_filter :student, :only => :show,:index
skip_load_and_authorize_resource
authorize_resource :only => [:index, :show]
layout 'facturacion/dashboard_layout'
def index
# id=params[:filter][:student]
end
def show
puts "im here"
ids=params[:student].to_i
print ids
# puts ids
#user =Academico::Student.find(params[:id])
end
private
def historys_params
params.require(:facturacion_history).permit(:student=>[:id])
end
end
routes.rb
resources :statements
resources :historys
index.html.erb
<div class="right_col" role="main">
<div class="">
<div class="clearfix"></div>
<div class="row">
<div class="clearfix"></div>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Historial Transacciones</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<% if notice.present?%>
<div class="alert alert-success">
×
<%= notice %>
</div>
<% end %>
<div class="table-responsive">
<div class="item form-group">
<%= form_tag facturacion_historys_path, :method => 'get',:class=>"form-horizontal form-label-left" do %>
<%= label_tag "Estudiante", nil, :class=>"control-label col-md-3 col-sm-3 col-xs-12" %>
<div class="col-md-6 col-sm-6 col-xs-12">
<%= collection_select(:student,:id, Academico::Student.all, :id,:full_name, {:include_blank => true, :required=>"required"},{:class=>"select2_single form-control",:required=>"required"}) %>
</div>
</div>
<div class="clearfix"></div>
<br>
<div class="clearfix"><br></div>
<div class="form-group">
<div class="row">
<div class="col-md-3" style="margin-left:100px;">
</div>
<div class="col-md-3" style="margin-left:100px;">
<button id="send" type="submit" class="btn btn-success">Generar</button>
</div>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
the form does not redirect me to the show view, after I choose an option, it returns the same index
he looked for information about it and found no solution my rake routes are as follows
Rake routes
facturacion/historys#index
POST /facturacion/historys(.:format) facturacion/historys#create
new_facturacion_history GET /facturacion/historys/new(.:format) facturacion/historys#new
edit_facturacion_history GET /facturacion/historys/:id/edit(.:format) facturacion/historys#edit
facturacion_history GET /facturacion/historys/:id(.:format) facturacion/historys#show
PATCH /facturacion/historys/:id(.:format) facturacion/historys#update
PUT /facturacion/historys/:id(.:format) facturacion/historys#update
DELETE /facturacion/historys/:id(.:format) facturacion/historys#destroy
I do not know what I am doing wrong or if I am or mitigating some step, I would be grateful for the help, thank you very much
In your form in index.html, you need the correct path /facturacion/historys/:id i.e. facturacion_history_path(:id) there is a typo in the path.
Note: You need add the id of the record as well.

Rails wrongly interpreting http method when adding new nested record

I've got a form with nested attributes fields, made with form_with model:
<%= form_with model: [ :admin, #event ], local: true, class: "event-form" do |form| %>
<%= form.hidden_field :event_category_id %>
<div class="row">
<div class='col-xs-12 col-sm-7'>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
Wersja Polska
</li>
<li role="presentation">Wersja Angielska</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane panel panel-default fade in active" id="<%= dom_id #event %>-pl-tab">
<div class='panel-body'>
<div class='checkbox'>
<label>
<%= form.check_box :pl_active, class: 'panel-activator' %>
Aktywna
</label>
</div>
...
and in that form i'm using fields_for nested attributes:
<div class='panel panel-default'>
<div class='panel-heading'>
<div class='row'>
<div class='col-xs-6'>
<%= form.label :event_variants %>
</div>
<div class='col-xs-6 text-right'>
<%=link_to 'Dodaj', new_admin_event_variant_path( event_id: #event, index: #event.event_variants.size ), id: "add-event-variant", class: 'btn btn-sm btn-primary', remote: true %>
</div>
</div>
</div>
<div class='panel-body event-variants sortable'>
<%- #event.event_variants.each_with_index do |event_variant, index| %>
<%= render partial: 'admin/event_variants/form', locals: { event_variant: event_variant, index: index } %>
<% end %>
</div>
</div>
and a partial looks like:
<div id="event_variant-<%= index %>" class='panel panel-default'>
<%= fields_for "event[event_variants_attributes][]", event_variant, child_index: index do |fields| %>
<%= fields.hidden_field :id %>
<%= fields.hidden_field :position %>
<%= fields.hidden_field :_destroy %>
<div class='panel-heading'>
<div class='row'>
<div class='col-xs-6 variant-title'>
<%= event_variant.pl_title || 'Nowy element' %>
</div>
<div class='col-xs-6 text-right'>
<label class='btn btn-sm btn-primary'>
<%= event_variant.image&.file.present? ? 'Zmień zdjęcie' : 'Dodaj zdjęcie' %>
<%= fields.file_field :image, style: 'display:none', class: 'add-image' %>
</label>
<div class='btn btn-sm btn-danger remove-variant'>Usuń</div>
</div>
</div>
</div>
<div class='image-container' style="background-image:url('<%= event_variant.image&.file.present? ? event_variant.image.url : image_path('no-image-icon') %>')" >
</div>
<div class='panel-body'>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
Wersja Polska
</li>
<li role="presentation">Wersja Angielska</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane panel panel-default fade in active" id="event_variant-<%= index %>-pl-tab">
<div class='panel-body'>
<div class='checkbox'>
<label>
<%= fields.check_box :pl_active, class: 'panel-activator' %>
Aktywna
</label>
</div>
<div class="form-group">
<%= fields.label :pl_title %>
<%= fields.text_field :pl_title, class: 'form-control', disabled: !event_variant.pl_active %>
</div>
<div class="form-group">
<%= fields.label :pl_description %>
<%= fields.text_field :pl_description, class: 'form-control', disabled: !event_variant.pl_active %>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane panel panel-default fade" id="event_variant-<%= index %>-en-tab">
<div class='panel-body'>
<div class='checkbox'>
<label>
<%= fields.check_box :en_active, class: 'panel-activator' %>
Aktywna
</label>
</div>
<div class="form-group">
<%= fields.label :en_title %>
<%= fields.text_field :en_title, class: 'form-control', disabled: !event_variant.en_active %>
</div>
<div class="form-group">
<%= fields.label :en_subtitle %>
<%= fields.text_field :en_description, class: 'form-control', disabled: !event_variant.en_active %>
</div>
</div>
</div>
</div>
</div>
<% end %>
</div>
thats attributes are has_many related with main model, so beside fields to edit each of nested model, I can click to render new fields_for partial to create nem nested record - common thing I guess:
<%=link_to 'Dodaj', new_admin_event_variant_path( event_id: #event, index: #event.event_variants.size ), id: "add-event-variant", class: 'btn btn-sm btn-primary', remote: true %>
going to:
def new
#event = Event.find params[:event_id]
#event_variant = #event.event_variants.build( pl_active: false, en_active: false )
#index = params[:index]
end
and rendering js.erb:
$('.event-variants').append("<%= j render( partial: 'form', locals: { event_variant: #event_variant, index: #index } ) %>")
the problem starts when i'm trying to edit main record. When I'm only changing values of fields, adding images, etc. no matter if in main or nested fields its working ok, sending PATCH, updating record and nested ones.
BUT:
when I'm trying to add new nested record, by those fields rendered via js.erb, form is send with POST instead of PATCH to route: /events/:id and of course its generating RoutingError:
Invalid or incomplete POST params
Started POST "/admin/events/14" for 127.0.0.1 at 2019-09-16 11:19:11 +0200
ActionController::RoutingError (No route matches [POST] "/admin/events/14"):
form attributes are not changing. HTML still looks like:
<div class="panel-body">
<form class="event-form" enctype="multipart/form-data" action="/admin/events/14" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="_method" value="patch">
<input type="hidden" name="authenticity_token" value="Z3Uhd6EgZ+N16P5MKbqLDs3F1d94iEokD4O5q63V04q/ofFblB5sRCmEO2m+coHayDrQ/zDNVHSzfSzmDGrxog==">
<input type="hidden" value="2" name="event[event_category_id]">
<div class="row">
<div class="col-xs-12 col-sm-7">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
Wersja Polska
</li>
<li role="presentation">Wersja Angielska</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane panel panel-default fade in active" id="event_14-pl-tab">
<div class="panel-body">
<div class="checkbox">
<label>
<input name="event[pl_active]" type="hidden" value="0">
<input class="panel-activator" type="checkbox" value="1" checked="checked" name="event[pl_active]">
Aktywna
</label>
...
even with _method field set to PATCH
even if I manualy set a method in form_with by method: #event.persisted? ? :patch : :post
Everything works correctly when no new nested record.
And last but not least, I'm not changing anything via js onSubmit nor onClick when submitting.
Any ideas what could went wrong here?
I got this problem when a form field wasn't valid.
name="blah[]" # this isn't valid
See ActionController::BadRequest (Invalid request parameters: expected Array (got Rack::QueryParser::Params) on ajax post
Putting a pry in this file helped me out
/2.7.4/lib/ruby/gems/2.7.0/gems/rack-2.2.3.1/lib/rack/method_override.rb
def method_override_param(req)
binding.pry
req.POST[METHOD_OVERRIDE_PARAM_KEY]

Resources