Unable to store data from my table into a hash map in rails?

I am trying to store all Patient full names into a hash map from my database table however I am getting the following error :

param is missing or the value is empty: patient 

on this line in my patients controller:

def patient_params
      params.require(:patient).permit(:Full_Name, :Age, :Sex, :Address, :PPS, :Medical_Card)
end

I am unsure where I am going wrong with this, any help would be greatly appreciated!

patients_controller.rb

  def allP
    # print out all
    p=Hash.new
    current_user.patients.all.each do |patient|
        p.store("Full Name", patient.Full_Name)
    end
  end

index.html.erb

<%= button_to "Some Button", :method=> "allP" %>

Error Log

Started POST "/patients?method=allP" for 127.0.0.1 at 2019-03-14 00:36:54 +0000
Processing by PatientsController#create as HTML
  Parameters: {"authenticity_token"=>"lo2SRaVmEAHUdpqgknqT9iKPijEypaJ+8PX5Ad1igd/VTBbnRWsZy7akIVBx9c3eQnEmh6lljGm1sfEIDNs4Eg==", "met

hod"=>"allP"}
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 2], ["LIMIT", 1
]]
  ↳ /Users/j/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Completed 400 Bad Request in 3ms (ActiveRecord: 0.3ms)



ActionController::ParameterMissing (param is missing or the value is empty: patient):

app/controllers/patients_controller.rb:83:in `patient_params'
app/controllers/patients_controller.rb:37:in `create'
728x90

1 Answers Unable to store data from my table into a hash map in rails?

Check out those parameters (formatted for readability):

Started POST "/patients?method=allP" for 127.0.0.1 at 2019-03-14 00:36:54 +0000
Processing by PatientsController#create as HTML
  Parameters: {
    "authenticity_token"=>"lo2SRaVmEAHUdpqgknqT9iKPijEypaJ+8PX5Ad1igd/VTBbnRWsZy7akIVBx9c3eQnEmh6lljGm1sfEIDNs4Eg==", 
    "method"=>"allP"
  }

So, when you say:

def patient_params
  params.require(:patient).permit(:Full_Name, :Age, :Sex, :Address, :PPS, :Medical_Card)
end

params.require(:patient) fails because, wait for it, params doesn't include :patient and you, well, required it.

6 days ago