Pinaev
Pinaev

Reputation: 48

There is an error when calling update action

<%= form_for(@object, url: obj_path) do |f| %>

    <%= f.label :Flow_ID %>:
    <%= select_tag "flow", options_from_collection_for_select(@flows, "id", "name") %><br><br>
    <%= f.label :Object_Type_ID %>:
    <%= select_tag "object_type", options_from_collection_for_select(@object_types, "id", "name") %><br><br>
    <%= f.label :name %>
    <%= f.text_field :name %><br><br>
    <%= f.label :label %>
    <%= f.text_field :label %><br><br>
    <%= f.submit "Update Object", class: "btn btn-success"  %><br>
    <%= link_to "Back", objs_path %>

<% end %>

This is edit.html.erb

class ObjsController < ApplicationController

   def update
     @object = Obj.find(params[:id])
     @object.flow_id = params[:flow]
     @object.object_type_id = params[:object_type]
     @object.update(object_params)
     redirect_to objs_url
   end

  private
   def object_params
     params.require(:object).permit(:name, :label)
   end
end

This is objs_controller.rb.

When I click update button, object_params is missing. Anyone knows what I have a mistake?

Upvotes: 0

Views: 51

Answers (2)

harika
harika

Reputation: 113

If your model name is Obj, then you have a mismatch. Either change Obj to Object or Object to Obj. I can further update my answer based on your response. Also provide the complete error log in your question.

Change the line

params.require(:object).permit(:name, :label)

to

params.require(:obj).permit(:name, :label)

That should solve the problem. strong parameters

Upvotes: 1

Pavan
Pavan

Reputation: 33542

param is missing or the value is empty: object

You should change

def object_params
  params.require(:object).permit(:name, :label)
end

to

def object_params
  params.require(:obj).permit(:name, :label)
end

As you model is Obj not Object

If you look into the params hash, you will see it with :obj key. So you need to use :obj not :object

Upvotes: 2

Related Questions