OK...so I renamed the table/model/controller and am getting a different
error based (likely) on the fact that I forgot to change the name
somewhere...
NameError in PatientApplicationsController#create
undefined local variable or method `patient_application_params' for
#<PatientApplicationsController:0x007f257dbdc9d8>
> # POST /patient_applications.json
> def create
> @patient_application = PatientApplication.new(patient_application_params)
>
> respond_to do |format|
> if @patient_application.save
The parameters are as follows:
>{"utf8"=>"✓",
>
"authenticity_token"=>"Rf9oXjSWGjhsPlc9MHMxKEFWPjHSS5sAqDA0Pdsi9nVO+qrlMgDsBEtObej9anvfcI42nigMUHmZ3cWQHbjiRA==",
> "patient_application"=>{"patients_ptID"=>"1",
> "pharm_manufacturers_phID"=>"1",
> "medications_rxnorm_ndc"=>"Tylenol",
> "app_status"=>"Pending",
> "date_init(1i)"=>"2015",
> "date_init(2i)"=>"2",
> "date_init(3i)"=>"8"},
> "commit"=>"Create Patient application"}
The updated controller is as follows:
class PatientApplicationsController < ApplicationController
before_action :set_patient_application, only: [:show, :edit, :update,
:destroy]
# GET /patient_applications
# GET /patient_applications.json
def index
@patient_applications = PatientApplication.all
end
# GET /patient_applications/1
# GET /patient_applications/1.json
def show
end
# GET /patient_applications/new
def new
@patient_application = PatientApplication.new
end
# GET /patient_applications/1/edit
def edit
end
# POST /patient_applications
# POST /patient_applications.json
def create
@patient_application =
PatientApplication.new(patient_application_params)
respond_to do |format|
if @patient_application.save
format.html { redirect_to @patient_application, notice: 'Patient
application was successfully created.' }
format.json { render :show, status: :created, location:
@patient_application }
else
format.html { render :new }
format.json { render json: @patient_application.errors, status:
:unprocessable_entity }
end
end
end
# PATCH/PUT /patient_applications/1
# PATCH/PUT /patient_applications/1.json
def update
respond_to do |format|
if @patient_application.update(application_params)
format.html { redirect_to @patient_application, notice: 'Patient
application was successfully updated.' }
format.json { render :show, status: :ok, location:
@patient_application }
else
format.html { render :edit }
format.json { render json: @patient_application.errors, status:
:unprocessable_entity }
end
end
end
# DELETE /patient_applications/1
# DELETE /patient_applications/1.json
def destroy
@patient_application.destroy
respond_to do |format|
format.html { redirect_to patient_applications_url, notice:
'Patient application was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between
actions.
def set_patient_application
@patient_application = PatientApplication.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the
white list through.
def application_params
params.require(:patient_application).permit(:patients_ptID,
:pharm_manufacturers_phID, :medications_rxnorm_ndc, :app_status,
:date_init)
end
end
However, the original error persists in every connected table I
have...such as the following:
ActiveRecord::AssociationTypeMismatch in DispensedMedsController#create
DispensedMed(#69899493618640) expected, got String(#8997680)
> # POST /dispensed_meds.json
> def create
> @dispensed_med = DispensedMed.new(dispensed_med_params)
>
> respond_to do |format|
> if @dispensed_med.save
The controller as follows:
class DispensedMedsController < ApplicationController
before_action :set_dispensed_med, only: [:show, :edit, :update,
:destroy]
# GET /dispensed_meds
# GET /dispensed_meds.json
def index
@dispensed_meds = DispensedMed.all
end
# GET /dispensed_meds/1
# GET /dispensed_meds/1.json
def show
end
# GET /dispensed_meds/new
def new
@dispensed_med = DispensedMed.new
end
# GET /dispensed_meds/1/edit
def edit
end
# POST /dispensed_meds
# POST /dispensed_meds.json
def create
@dispensed_med = DispensedMed.new(dispensed_med_params)
respond_to do |format|
if @dispensed_med.save
format.html { redirect_to @dispensed_med, notice: 'Dispensed med
was successfully created.' }
format.json { render :show, status: :created, location:
@dispensed_med }
else
format.html { render :new }
format.json { render json: @dispensed_med.errors, status:
:unprocessable_entity }
end
end
end
# PATCH/PUT /dispensed_meds/1
# PATCH/PUT /dispensed_meds/1.json
def update
respond_to do |format|
if @dispensed_med.update(dispensed_med_params)
format.html { redirect_to @dispensed_med, notice: 'Dispensed med
was successfully updated.' }
format.json { render :show, status: :ok, location:
@dispensed_med }
else
format.html { render :edit }
format.json { render json: @dispensed_med.errors, status:
:unprocessable_entity }
end
end
end
# DELETE /dispensed_meds/1
# DELETE /dispensed_meds/1.json
def destroy
@dispensed_med.destroy
respond_to do |format|
format.html { redirect_to dispensed_meds_url, notice: 'Dispensed
med was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between
actions.
def set_dispensed_med
@dispensed_med = DispensedMed.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the
white list through.
def dispensed_med_params
params.require(:dispensed_med).permit(:dis_date, :patients_ptID,
:inventory_invID)
end
end
And the respective form:
<%= form_for(@dispensed_med) do |f| %>
<% if @dispensed_med.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@dispensed_med.errors.count, "error") %>
prohibited this dispensed_med from being saved:</h2>
<ul>
<% @dispensed_med.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :dis_date %><br>
<%= f.date_select :dis_date %>
</div>
<div class="field">
<%= f.label :patients_ptID %><br>
<%= f.number_field :patients_ptID %>
</div>
<div class="field">
<%= f.label :inventory_invID %><br>
<%= f.number_field :inventory_invID %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
As well as the model:
class DispensedMed < ActiveRecord::Base
has_one :patient
has_one :patients_ptID, :through => :patient, :source =>
:dispensed_meds, dependent: :nullify
has_one :inventory
has_one :inventory_invID, :through => :inventory, :source =>
:dispensed_meds, dependent: :nullify
end
Once again, thanks so so so much. It means a ton.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ea37f92ffdcb51a72139cc885da3a7f3%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment