Display all values in the show.html.erb originally selected in the form

Hello,

Currently, my issue is that I cannot see the values I have selected in
my Appointment form. This is the code in my appointments/form.html.erb.

<%= f.label :appointment_time %>

<%= select “obj”, “test”, timeslots.map.with_index{ |name, index|
[name,
index] } %>

<div class="field">
  <%= f.label :diagnostic_code %><br>
  <%= f.collection_select :diagnostic_code_id, DiagnosticCode.all,

:id, :diagnostic_code_id %>

<%= f.label :appt_completion %>
<%= radio_button_tag(:appt_completion, "yes") %> <%= label_tag(:appt_completion_yes, "Appointment Completed") %> <%= radio_button_tag(:appt_completion, "no") %> <%= label_tag(:appt_completion_no, "Appointment Not Completed") %>
 I have this in the appointments/show.html.erb:

Appointment Time: <%= @appointment.appointment_time %>

Diagnostic Code: <%= @appointment.diagnostic_code_id %>

Appointment Completion Status: <%= @appointment.appt_completion %>

I think my problem may have resulted from the manner I added and
modified columns using multiple migrations to the Appointment table.
Attached is my current design. My design is not concrete, I am looking
for suggestions and guidance so I really appreciate any assistance.

My main goal though is to get this show operation working.

On Mon, Dec 1, 2014 at 2:33 PM, Dmoneyzzz D. [email protected]
wrote:

Currently, my issue is that I cannot see the values I have selected in
my Appointment form.

 I have this in the appointments/show.html.erb:

<%= @appointment.appointment_time %>

So what do you see there? Use view source.

The likely cause of missing values is either

  1. the values were never inserted into the DB to start with
    or
  2. you’re not setting @appointment in your controller

Either of those should be easy to identify. Start by looking at your
DB. If the data isn’t there, look at your logs; are the params being
received what you expect? Does your model have validations that
might be failing?


Hassan S. ------------------------ [email protected]

twitter: @hassan

Hassan S. wrote in post #1163781:

On Mon, Dec 1, 2014 at 2:33 PM, Dmoneyzzz D. [email protected]
wrote:
So what do you see there? Use view source.

The likely cause of missing values is either

  1. the values were never inserted into the DB to start with
    or
  2. you’re not setting @appointment in your controller

Either of those should be easy to identify. Start by looking at your
DB. If the data isn’t there, look at your logs; are the params being
received what you expect? Does your model have validations that
might be failing?


Hassan S. ------------------------ [email protected]
Hassan Schroeder | about.me
twitter: @hassan

Hello, I reviewed my seeds.rb, development log, and looked throughout my
project and I have come to the conclusion that my values are not sent to
the db.

I have this code in my appointments controller

def appointment_params
params.require(:appointment).permit(:physician_id, :patient_id,
:reason, :appointment_date, :appointment_time, :notes, :appt_completion)
end

And I made sure each field existed in the schema.rb.

I searched through my development log and it appears that the params are
filled when the appointment is created. For the array I created called
:appointment_time, I’m pretty sure those value are sent to the db as an
index number. I am really lost but thanks for your help so far.

Hassan S. wrote in post #1163795:

On Mon, Dec 1, 2014 at 4:40 PM, Dmoneyzzz D. [email protected]
wrote:
use the rails console to examine e.g. Appointment.last.

Hassan S. ------------------------ [email protected]
Hassan Schroeder | about.me
twitter: @hassan

Hey, thanks for your help thus far.

I ran the rails console and entered Appointment.last and found that
these three fields were entered into the database as nil even though
they were selected in the Appointment form.

#<Appointment id: 22, patient_id: 8, appointment_date: “2014-12-01”,
created_at: “2014-12-01 22:23:26”, updated_at: “2014-12-01 22:23:26”,
physician_id: 4, reason: “asfafs”, notes: “sfa”, diagnostic_code_id:
nil, appt_completion: nil, appointment_time: nil>

So I’m not sure of my next step code wise, but I know I should figure
out how to get the select in the form to create and update info to send
to the db.

On Mon, Dec 1, 2014 at 4:40 PM, Dmoneyzzz D. [email protected]
wrote:

Hello, I reviewed my seeds.rb, development log, and looked throughout my
project and I have come to the conclusion that my values are not sent to
the db.

Wrong answer. Open a console and look. You can use dbconsole
if you’re comfortable with whatever DB you’re using (and you should
be) or use the rails console to examine e.g. Appointment.last.

I searched through my development log and it appears that the params are
filled when the appointment is created.

Wait, then is the appointment being created? Because that implies
that the Appointment “create” action was successful. That doesn’t
match with what you previously said.

Maybe you could show us (preferably via a gist) a create sequence
from your log.


Hassan S. ------------------------ [email protected]

twitter: @hassan

On Mon, Dec 1, 2014 at 6:15 PM, Dmoneyzzz D. [email protected]
wrote:

out how to get the select in the form to create and update info to send
to the db.

You should look at the log file to see exactly what parameters are
being sent to your create action.


Hassan S. ------------------------ [email protected]

twitter: @hassan

Hassan S. wrote in post #1163800:

On Mon, Dec 1, 2014 at 6:15 PM, Dmoneyzzz D. [email protected]
wrote:

out how to get the select in the form to create and update info to send
to the db.

You should look at the log file to see exactly what parameters are
being sent to your create action.


Hassan S. ------------------------ [email protected]
Hassan Schroeder | about.me
twitter: @hassan

[1m[35mSQL (1.0ms)[0m INSERT INTO “physicians” (“created_at”, “name”,
“updated_at”) VALUES (?, ?, ?) [[“created_at”, “2014-12-02
00:33:48.986623”], [“name”, “Lewis Louis”], [“updated_at”, “2014-12-02
00:33:48.986623”]]
[1m[36m (2.0ms)[0m [1mcommit transaction[0m

These are the parameters that are being transferred to the db. So now I
need to find the location of these parameters in my controller, right?

Hassan S. wrote in post #1163802:

On Mon, Dec 1, 2014 at 6:30 PM, Dmoneyzzz D. [email protected]
wrote:

These are the parameters that are being transferred to the db. So now I
need to find the location of these parameters in my controller,
Maybe there’s another
more pertinent log entry?

Hassan S. ------------------------

I have this code in my log. It appears as though these values have been
entered as null in the db. So I’m thinking I may need helper methods to
gather the values in the select.

TO “appointments”
(“id”,“patient_id”,“appointment_date”,“created_at”,“updated_at”,“physician_id”,“reason”,“notes”,“diagnostic_id”,“diagnostic_code_id”,“appt_completion”,“appointment_time”)
VALUES (22, 8, ‘2014-12-01’, ‘2014-12-01 22:23:26.455231’, ‘2014-12-01
22:23:26.455231’, 4, ‘asfafs’, ‘sfa’, NULL, NULL, NULL, NULL)

On Mon, Dec 1, 2014 at 7:34 PM, Dmoneyzzz D. [email protected]
wrote:

TO “appointments”

(“id”,“patient_id”,“appointment_date”,“created_at”,“updated_at”,“physician_id”,“reason”,“notes”,“diagnostic_id”,“diagnostic_code_id”,“appt_completion”,“appointment_time”)

VALUES (22, 8, ‘2014-12-01’, ‘2014-12-01 22:23:26.455231’, ‘2014-12-01
22:23:26.455231’, 4, ‘asfafs’, ‘sfa’, NULL, NULL, NULL, NULL)

OK, that’s a SQL statement, but what do the actual parameters
look like?


Hassan S. ------------------------ [email protected]

twitter: @hassan

On Mon, Dec 1, 2014 at 6:30 PM, Dmoneyzzz D. [email protected]
wrote:

[1m[35mSQL (1.0ms)[0m INSERT INTO “physicians”

These are the parameters that are being transferred to the db. So now I
need to find the location of these parameters in my controller, right?

Uh, well. You were talking about an Appointment before.

How is that related to a “physicians” table? Maybe there’s another
more pertinent log entry?


Hassan S. ------------------------ [email protected]

twitter: @hassan

Hassan S. wrote in post #1163806:

On Mon, Dec 1, 2014 at 7:34 PM, Dmoneyzzz D. [email protected]
wrote:

TO “appointments”

(“id”,“patient_id”,“appointment_date”,“created_at”,“updated_at”,“physician_id”,“reason”,“notes”,“diagnostic_id”,“diagnostic_code_id”,“appt_completion”,“appointment_time”)

VALUES (22, 8, ‘2014-12-01’, ‘2014-12-01 22:23:26.455231’, ‘2014-12-01
22:23:26.455231’, 4, ‘asfafs’, ‘sfa’, NULL, NULL, NULL, NULL)

OK, that’s a SQL statement, but what do the actual parameters
look like?


Hassan S. ------------------------ [email protected]
Hassan Schroeder | about.me
twitter: @hassan

Parameters: {“utf8”=>“✓”,
“authenticity_token”=>“3aeYhNBVYaFdHpPHWR5qpoD3QDB8PRUJIiR94WC1kag=”,
“appointment”=>{“physician_id”=>“5”, “patient_id”=>“12”,
“reason”=>“Because”, “appointment_date(1i)”=>“2014”,
“appointment_date(2i)”=>“11”, “appointment_date(3i)”=>“30”,
“diagnostic_code_id”=>“3”, “notes”=>“Easy”}, “commit”=>“Create
Appointment”}

I found this in my development log. In particular, these parameters do
not contain appointment_time but I am sure I added the column
respectively.

On 1 December 2014 at 22:33, Dmoneyzzz D. [email protected]
wrote:

Hello,

Currently, my issue is that I cannot see the values I have selected in
my Appointment form. This is the code in my appointments/form.html.erb.

I think it may be possible that you are not fully grasping some of the
fundamentals of Rails. I think you could find it useful to work right
through a good tutorial such as railstutorial.org, (which is free to
use online). That should show you the basics of Rails.

Colin

On Dec 1, 2014, at 10:02 PM, Dmoneyzzz D. [email protected]
wrote:

In particular, these parameters do
not contain appointment_time but I am sure I added the column
respectively.

The parameters reflect what’s coming from the browser, what is submitted
with the form. So this has nothing to do with the database. You need to
look at your form, at your input fields, their names & ids–first look
at the .erb source and if you don’t right away see why time is different
and not coming through, then look at the actual html that is generated,
inspect the input elements, look at their names & ids.

Scott R. wrote in post #1163809:

The parameters reflect what’s coming from the browser, what is submitted
with the form. So this has nothing to do with the database. You need to
look at your form, at your input fields, their names & ids–first look
at the .erb source and if you don’t right away see why time is different
and not coming through, then look at the actual html that is generated,
inspect the input elements, look at their names & ids.

By viewing the page source of my browser and comparing the results to my
index.html.erb, I can conclude that the values have not been sent to the
db from the form. After updating a record, I can see that a value for a
boolean field is not recorded to my db and therefore not shown on the
index.html.erb browser source code.

I did a db:migrate, and now I am searching all my project files for
params of appointment to make sure all fields are included on create and
update. In my controller, the appointment params are set up precisely
so that create and updates require all fields. I just don’t know how
appointment_date can be sent to the db and not appt_completion if they
were both created in the same manner.

I’m have been looking over the online copy of railstutorials.org for the
past two hours looking for a solution to my form submit to db problem.

On Tue, Dec 2, 2014 at 10:39 AM, Dmoneyzzz D. [email protected]
wrote:

… I just don’t know how
appointment_date can be sent to the db and not appt_completion if they
were both created in the same manner.

And you probably won’t until you stop wasting time and look at
the actual parameters as they appear in your log.

Log files are there for a reason.


Hassan S. ------------------------ [email protected]

twitter: @hassan

On Dec 2, 2014, at 12:00 PM, Scott R. [email protected] wrote:

Note what’s different in your form between appt_completion and other input
elements: you’re using plain tag helpers instead of the form methods,
radio_button_tag instead of f.radio_button, which means the appt_completion
parameters are not going to be associated with the record associated with the form
via form_for.

And while I was typing this, Hassan gave another hint, which is EXTREMELY
important. Look at the log when you submit the form, and examine the parameters.
You MUST do this if you want to see what is happening.

The tutorial should help you understand how form data is submitted, how RoR
parses it, and how it is passed through to your controller action. It’s not magic,
the forms are just HTML, and the RoR methods that generate input elements use
conventions regarding the element names & ids used in that HTML, and then other
RoR methods expect those conventions when receiving the data from the browser.

But ultimately, the parameters as parsed by RoR are the first place to look for
“where did my data go” questions, because that’s where you figure out whether the
form is not configured to submit the data correctly, or whether the problem is in
how you’re handling the data–is the problem in the form or the controller.

Also I still stand by my advice from yesterday: inspect the elements in
the browser, look at how they’re named. Then look at the data sent by
the browser to the server, see the name/value pairs. Then look at the
params, see how RoR uses the names to structure the params.

On Dec 2, 2014, at 11:39 AM, Dmoneyzzz D. [email protected]
wrote:

I just don’t know how
appointment_date can be sent to the db and not appt_completion if they
were both created in the same manner.

Note what’s different in your form between appt_completion and other
input elements: you’re using plain tag helpers instead of the form
methods, radio_button_tag instead of f.radio_button, which means the
appt_completion parameters are not going to be associated with the
record associated with the form via form_for.

And while I was typing this, Hassan gave another hint, which is
EXTREMELY important. Look at the log when you submit the form, and
examine the parameters. You MUST do this if you want to see what is
happening.

The tutorial should help you understand how form data is submitted, how
RoR parses it, and how it is passed through to your controller action.
It’s not magic, the forms are just HTML, and the RoR methods that
generate input elements use conventions regarding the element names &
ids used in that HTML, and then other RoR methods expect those
conventions when receiving the data from the browser.

But ultimately, the parameters as parsed by RoR are the first place to
look for “where did my data go” questions, because that’s where you
figure out whether the form is not configured to submit the data
correctly, or whether the problem is in how you’re handling the data–is
the problem in the form or the controller.

Colin L. wrote in post #1163860:

On 2 December 2014 at 18:39, Dmoneyzzz D. [email protected]
wrote:


I’m have been looking over the online copy of railstutorials.org for the
past two hours looking for a solution to my form submit to db problem.

Don’t spend two hours looking over it for a solution to this
particular problem. Take a few days out and work right through it,
including doing the exercises. There is no short cut to building
understanding.

Colin

I do agree Colin. I’m just in a pickle (and I am responsible), but I
appreciate all the assistance offered by this community. I’m moving
forward now, thanks everyone.

On 2 December 2014 at 18:39, Dmoneyzzz D. [email protected]
wrote:


I’m have been looking over the online copy of railstutorials.org for the
past two hours looking for a solution to my form submit to db problem.

Don’t spend two hours looking over it for a solution to this
particular problem. Take a few days out and work right through it,
including doing the exercises. There is no short cut to building
understanding.

Colin

Hello, I do have one more question.

After reviewing my development log and creating several appointments, I
see that I am making a successful POST from the form with the
appointment_time containing an index and value.

However, when the SQL insert statement is executed, the appointment_time
param disappears. I have created the field as a String, the select box
is an array dropdown.

I have ferociously reviewed the Appointment controller, test controller,
and adjusted all files in the view to reflect the correct field name. I
check usages of the other ids and matched locations and I still cannot
get my value to display on the show or index page.

This code is in my controller for both create and update methods:

@appointment = 

Appointment.new(params[:appointment].permit(:physician_id, :patient_id,
:reason, :appointment_date, :appointment_time, :diagnostic_code_id,
:notes, :appt_completion))

This was retrieved from my log (appointment_time is my focus)

Processing by AppointmentsController#create as HTML
Parameters: {“utf8”=>“✓”,
“authenticity_token”=>“3aeYhNBVYaFdHpPHWR5qpoD3QDB8PRUJIiR94WC1kag=”,
“appointment”=>{“physician_id”=>“4”, “patient_id”=>“8”,
“reason”=>“fdsdfs”, “appointment_date(1i)”=>“2014”,
“appointment_date(2i)”=>“12”, “appointment_date(3i)”=>“3”,
“diagnostic_code_id”=>“1”, “notes”=>“sdfsdfs”,
“appt_completion”=>“true”}, “appointment_time”=>{“test”=>“7”},
“commit”=>“Create Appointment”}
[1m[35m (0.0ms)[0m begin transaction
[1m[36mSQL (1.0ms)[0m [1mINSERT INTO “appointments”
(“appointment_date”, “appt_completion”, “created_at”,
“diagnostic_code_id”, “notes”, “patient_id”, “physician_id”, “reason”,
“updated_at”) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)[0m
[[“appointment_date”, “2014-12-03”], [“appt_completion”, “t”],
[“created_at”, “2014-12-03 00:04:58.420420”], [“diagnostic_code_id”,
1.0], [“notes”, “sdfsdfs”], [“patient_id”, 8], [“physician_id”, 4],
[“reason”, “fdsdfs”], [“updated_at”, “2014-12-03 00:04:58.420420”]]

I have been tabbing stack overflow, if you have a resource then please
link it, thanks.