ruby 2.4.1 rails 5.2.3
worker_fields_controller
def new
@field = WorkerField.new
end
def create
@field = WorkerField.new(field_params)
@field.save
respond_to do |format|
format.js
end
end
new.html.erb
<%= form_for(@field, remote: true,authenticity_token: true,html: {class: "navbar-left"}) do |form| %>
<%= form.text_field :field_name,id:'tag_name',class: 'form-control' ,placeholder: "标签名"%>
<%= form.submit "创建", class: "btn btn-primary " %>
<% end %>
create.js.erb
console.log("111111111111111111")
报错:ActionController::UnknownFormat
Request info:
Request parameters
{"utf8"=>"✓", "authenticity_token"=>"6voe3N6JOISSuzCArQjVZnnhFLnrd7y2IOgemnZbxNdoFuhsouWqmP7PH0JA/iS0uVjnoFE+coaTEh/UNqoLMA==", "hr_worker_field"=>{"field_name"=>"xxx"}, "controller"=>"hr/worker_fields", "action"=>"create"}
Rack session
(Object too large. Modify ActionDispatch::Request::Session#inspect or adjust BetterErrors.maximum_variable_inspect_size if you need to see it.)
log:
Started POST "/hr/worker_fields" for ::1 at 2020-07-13 19:24:02 +0800
Processing by Hr::WorkerFieldsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fTZiZhfkuxYwMC7+vUeOM0dcEuPslmTLHbJD5k/mJJn/2pTWa4gpClxEATxQsX/hh+Xh+lbfqvuuSEKoDxfrfg==", "hr_worker_field"=>{"field_name"=>"xxx"}}
Fdn::User Load (0.4ms) SELECT `fdn_users`.* FROM `fdn_users` WHERE `fdn_users`.`id` = 1 LIMIT 1
↳ app/helpers/fdn/user_sessions_helper.rb:22
Fdn::UserInformation Load (0.3ms) SELECT `fdn_user_informations`.* FROM `fdn_user_informations` WHERE `fdn_user_informations`.`user_id` = 1
↳ app/helpers/fdn/user_sessions_helper.rb:22
(0.1ms) BEGIN
↳ app/controllers/hr/worker_fields_controller.rb:17
Hr::WorkerField Create (0.3ms) INSERT INTO `hr_worker_fields` (`field_name`, `created_at`, `updated_at`) VALUES ('xxx', '2020-07-13 19:24:02', '2020-07-13 19:24:02')
↳ app/controllers/hr/worker_fields_controller.rb:17
(3.8ms) COMMIT
↳ app/controllers/hr/worker_fields_controller.rb:17
Completed 500 in 16ms (ActiveRecord: 4.9ms)
ActionController::UnknownFormat - ActionController::UnknownFormat:
app/controllers/hr/worker_fields_controller.rb:18:in `create'
Started POST "/__better_errors/39432d2893672a62/variables" for ::1 at 2020-07-13 19:24:02 +0800
也网上看了些别人的情况,在我这没啥用。
还试着在表单加 format::js 的参数
实在不知道解决方案