Rails 5 - form not updating - param is missing or the value is empty: tag

Dimitri de Ruiter Source

In my rails 5 app, I have a form (below) that is loading correctly, yet not updating. No notification of errors (should pass all validations (only on presence = true)).

Error

param is missing or the value is empty: tag

pointing to the tag_params method.

All help, suggestions, improvement, simplification welcome!

enter image description here

Controller

def update
  tagable = detect_tagable
  @tag = tagable.tags.find(params[:id])
  @tag.update(tag_params)
  render '_tag_update'
end

def tag_params
  params.require(:tag).permit(:content, :location, :tagtype_id, annotation_attributes: { annotation_ids:[] }, document_attributes: { document_ids:[] })
end

Routes

Rails.application.routes.draw do
  root 'dashboard#index'
  devise_for :users
  resources :users, :documenttypes, :tagtypes, :business_partners

  resources :documents do
    resources :comments, :tags
    get "pdf", on: :member 

  end

  resources :annotations do
    resources :comments, :tags
    get "pdf", on: :member

end

get "annotations/:id/annotate" => "annotations#annotate", as: 'annotate'

Form:

<%= simple_form_for [@tag.tagable, @tag], html: { class: 'form-horizontal', multipart: true },
    wrapper: :horizontal_form,
    wrapper_mappings: {
        check_boxes: :horizontal_radio_and_checkboxes,
        radio_buttons: :horizontal_radio_and_checkboxes,
        boolean: :horizontal_boolean
      } do |f| %>

    <%= f.error_notification %>

    <%= f.input :content, placeholder: 'Tagged content'%>

    <%= f.association :tagtype, prompt: 'Select tag type', :collection => Tagtype.active.order(:name).where(:documenttype => @tag.tagable.documenttype_id) %>

    <%= f.input :location, prompt: 'add as x1, y1, x2, y2' %>

    <%= f.button :submit %>

<% end -%>

Rails server returns this (appears to be executed)

Started PATCH "/annotations/6/tags/46" for ::1 at 2016-10-15 16:15:09 +0200 Processing by TagsController#update as HTML Parameters: {"authenticity_token"=>"7JMnYxy00zQXLIEfETSGWcMxPQFwNMYRJRyCeL9RMAQYtLygrf3UjamlZQdR/ajgTY2wH6DKOTeLE6yAUqbc6w==", "annotation_id"=>"6", "id"=>"46"} User Load (1.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 6], ["LIMIT", 1]] Annotation Load (1.1ms) SELECT "annotations".* FROM "annotations" WHERE "annotations"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]] Tag Load (1.0ms) SELECT "tags".* FROM "tags" WHERE "tags"."tagable_id" = $1 AND "tags"."tagable_type" = $2 AND "tags"."id" = $3 LIMIT $4 [["tagable_id", 6], ["tagable_type", "Annotation"], ["id", 46], ["LIMIT", 1]] (0.2ms) BEGIN Tagtype Load (0.5ms) SELECT "tagtypes".* FROM "tagtypes" WHERE "tagtypes"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]] (0.2ms) COMMIT Rendering tags/_tag_update.html.erb within layouts/application Annotation Load (0.4ms) SELECT "annotations".* FROM "annotations" WHERE "annotations"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]] Tagtype Load (1.0ms) SELECT "tagtypes".* FROM "tagtypes" WHERE "tagtypes"."active" = $1 AND "tagtypes"."documenttype_id" = 2 ORDER BY "tagtypes"."name" ASC [["active", true]] Rendered tags/_tag_update.html.erb within layouts/application (43.0ms) Rendered shared/_menu.html.erb (2.9ms) Completed 200 OK in 220ms (Views: 203.3ms | ActiveRecord: 6.1ms)

ruby-on-rails

Answers

comments powered by Disqus