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

124 views
Skip to first unread message

Dmoneyzzz Darko

unread,
Dec 1, 2014, 5:34:30 PM12/1/14
to rubyonra...@googlegroups.com
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.

<div class="field">
<%= f.label :appointment_time %><br>

<%= select "obj", "test", timeslots.map.with_index{ |name, index|
[name,
index] } %>
</div>

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

<div class="field">
<%= f.label :appt_completion %><br>
<%= 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") %>
</div>


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

<p>
<strong>Appointment Time:</strong>
<%= @appointment.appointment_time %>
</p>

<p>
<strong>Diagnostic Code:</strong>
<%= @appointment.diagnostic_code_id %>
</p>

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

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.

Attachments:
http://www.ruby-forum.com/attachment/10306/appt_index.jpg
http://www.ruby-forum.com/attachment/10307/appt_form.jpg


--
Posted via http://www.ruby-forum.com/.

Hassan Schroeder

unread,
Dec 1, 2014, 6:12:34 PM12/1/14
to rubyonrails-talk
On Mon, Dec 1, 2014 at 2:33 PM, Dmoneyzzz Darko <li...@ruby-forum.com> 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 Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Dmoneyzzz Darko

unread,
Dec 1, 2014, 7:40:56 PM12/1/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163781:
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 Schroeder

unread,
Dec 1, 2014, 8:48:05 PM12/1/14
to rubyonrails-talk
On Mon, Dec 1, 2014 at 4:40 PM, Dmoneyzzz Darko <li...@ruby-forum.com> 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.

Dmoneyzzz Darko

unread,
Dec 1, 2014, 9:15:34 PM12/1/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163795:
> On Mon, Dec 1, 2014 at 4:40 PM, Dmoneyzzz Darko <li...@ruby-forum.com>
> wrote:
> use the rails console to examine e.g. Appointment.last.
>
> Hassan Schroeder ------------------------ hassan.s...@gmail.com
> http://about.me/hassanschroeder
> 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.

Hassan Schroeder

unread,
Dec 1, 2014, 9:22:13 PM12/1/14
to rubyonrails-talk
On Mon, Dec 1, 2014 at 6:15 PM, Dmoneyzzz Darko <li...@ruby-forum.com> wrote:

> 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.

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

--

Dmoneyzzz Darko

unread,
Dec 1, 2014, 9:30:58 PM12/1/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163800:
[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 Schroeder

unread,
Dec 1, 2014, 9:46:12 PM12/1/14
to rubyonrails-talk
On Mon, Dec 1, 2014 at 6:30 PM, Dmoneyzzz Darko <li...@ruby-forum.com> 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?

Dmoneyzzz Darko

unread,
Dec 1, 2014, 10:36:48 PM12/1/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163802:
> On Mon, Dec 1, 2014 at 6:30 PM, Dmoneyzzz Darko <li...@ruby-forum.com>
> 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 Schroeder ------------------------


I have this code in my log. It appears as though these values have been
entered as null in the db.

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)

Hassan Schroeder

unread,
Dec 1, 2014, 11:36:46 PM12/1/14
to rubyonrails-talk
On Mon, Dec 1, 2014 at 7:34 PM, Dmoneyzzz Darko <li...@ruby-forum.com> 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?

Dmoneyzzz Darko

unread,
Dec 2, 2014, 12:04:25 AM12/2/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163806:
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.

Scott Ribe

unread,
Dec 2, 2014, 12:12:12 AM12/2/14
to rubyonra...@googlegroups.com, Dmoneyzzz Darko
On Dec 1, 2014, at 10:02 PM, Dmoneyzzz Darko <li...@ruby-forum.com> 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 Ribe
scott...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Colin Law

unread,
Dec 2, 2014, 5:53:30 AM12/2/14
to rubyonra...@googlegroups.com
On 1 December 2014 at 22:33, Dmoneyzzz Darko <li...@ruby-forum.com> 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

Dmoneyzzz Darko

unread,
Dec 2, 2014, 1:40:58 PM12/2/14
to rubyonra...@googlegroups.com
Scott Ribe 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.

Attachments:
http://www.ruby-forum.com/attachment/10310/appt_form.jpg
http://www.ruby-forum.com/attachment/10311/appt_controller.jpg
http://www.ruby-forum.com/attachment/10312/appt-index.jpg

Hassan Schroeder

unread,
Dec 2, 2014, 1:48:04 PM12/2/14
to rubyonrails-talk
On Tue, Dec 2, 2014 at 10:39 AM, Dmoneyzzz Darko <li...@ruby-forum.com> 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.

Scott Ribe

unread,
Dec 2, 2014, 2:01:33 PM12/2/14
to rubyonra...@googlegroups.com, Dmoneyzzz Darko
On Dec 2, 2014, at 11:39 AM, Dmoneyzzz Darko <li...@ruby-forum.com> 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.

Scott Ribe

unread,
Dec 2, 2014, 2:12:59 PM12/2/14
to rubyonra...@googlegroups.com, Dmoneyzzz Darko

> On Dec 2, 2014, at 12:00 PM, Scott Ribe <scott...@elevated-dev.com> 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.

Colin Law

unread,
Dec 2, 2014, 3:55:07 PM12/2/14
to rubyonra...@googlegroups.com
On 2 December 2014 at 18:39, Dmoneyzzz Darko <li...@ruby-forum.com> 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

Dmoneyzzz Darko

unread,
Dec 2, 2014, 5:22:50 PM12/2/14
to rubyonra...@googlegroups.com
Colin Law wrote in post #1163860:
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.

Dmoneyzzz Darko

unread,
Dec 2, 2014, 7:44:51 PM12/2/14
to rubyonra...@googlegroups.com
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.

Scott Ribe

unread,
Dec 2, 2014, 8:00:55 PM12/2/14
to rubyonra...@googlegroups.com, Dmoneyzzz Darko
On Dec 2, 2014, at 5:44 PM, Dmoneyzzz Darko <li...@ruby-forum.com> wrote:
>
> 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"]]

Let me re-format the parameters for you a little and see if you can spot the problem:

{
"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"
}

Dmoneyzzz Darko

unread,
Dec 2, 2014, 8:16:40 PM12/2/14
to rubyonra...@googlegroups.com
Scott Ribe wrote in post #1163866:
> {
> "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"
> }


Is my problem the formatting of the appointment_time field in the
appointments params? Or is the value that is planned for insert
constrained by a single string input such as "7" rather than "test" =>
"7"?

I tried to remove the "test" => segment to just leave the index, or even
better retrieve the value. I don't see any spelling errors, but I do
know the insert is not typical of String values.

Walter Lee Davis

unread,
Dec 2, 2014, 8:34:36 PM12/2/14
to rubyonra...@googlegroups.com
I think he's trying to point out to you that the appointment_time field is not inside the appointment hash. So when that hash is used to update the @appointment instance, that value will not be added to it. It comes back around to how your form element was made. If you used the "bound" form helpers, as in f.text_field(:appointment_time) to make it, then the name attribute in the HTML would be <input name="appointment[appointment_time]" ...> and the value of that variable would be in the appointment hash.

Walter

>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/13ff08f5365250979047979bcf8a3909%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Dmoneyzzz Darko

unread,
Dec 2, 2014, 8:53:23 PM12/2/14
to rubyonra...@googlegroups.com
Walter Davis wrote in post #1163868:
> On Dec 2, 2014, at 8:15 PM, Dmoneyzzz Darko <li...@ruby-forum.com>
> wrote:
>
>>> "appointment_date(3i)"=>"3",
>>
appointment_time field
> is not inside the appointment hash. So when that hash is used to update
> the @appointment instance, that value will not be added to it. It comes
> back around to how your form element was made. If you used the "bound"
> form helpers, as in f.text_field(:appointment_time) to make it, then the
> name attribute in the HTML would be <input
> name="appointment[appointment_time]" ...> and the value of that variable
> would be in the appointment hash.
>
> Walter

I do understand this. I tried to input f.select or form.select for this
array drop down but I recieved an error for both so I left select alone
and then it displayed. So I was thinking of encapsulating my array drop
down into a bigger form element. I have f.label on the line above but
the array select would not run with the f.

Hassan Schroeder

unread,
Dec 2, 2014, 8:58:27 PM12/2/14
to rubyonrails-talk
On Tue, Dec 2, 2014 at 5:51 PM, Dmoneyzzz Darko <li...@ruby-forum.com> wrote:

> I do understand this. I tried to input f.select or form.select for this
> array drop down but I recieved an error for both so I left select alone
> and then it displayed.

"displayed", great, but it doesn't work. Not a good tradeoff :-)

What was the error? What did you find when you googled that error?
How did your code compare to the documentation for that method?

Dmoneyzzz Darko

unread,
Dec 2, 2014, 10:30:20 PM12/2/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163871:
undefined method `merge' for #<Array:0x5c68788> in
appointments/_form.html.erb

<%= f.select "appointment_time", "test", timeslots.map.with_index{
|name, index|
[name,
name] } %>

I found other examples undefined method 'merge' but did not find a
solution although I found direction to create my array and array
handling method in the controller. I tried different ways to display
the array dropdown and the code above (without the f.) was the first
time I was able to see the array in dropdown form. It felt like a
relief.

Hassan Schroeder

unread,
Dec 2, 2014, 10:54:54 PM12/2/14
to rubyonrails-talk
On Tue, Dec 2, 2014 at 7:29 PM, Dmoneyzzz Darko <li...@ruby-forum.com> wrote:

> undefined method `merge' for #<Array:0x5c68788> in
> appointments/_form.html.erb

OK, good, but --

>> How did your code compare to the documentation for that method?

> <%= f.select "appointment_time", "test", timeslots.map.with_index{
> |name, index| [name, name] } %>

From the ActionView::Helpers::FormBuilder doc example:

<%= f.select :person_id, Person.all.collect { |p| [ p.name, p.id ] },
include_blank: true %>

How do those two method signatures differ? Hint: what does "test"
in the first one represent?

Dmoneyzzz Darko

unread,
Dec 2, 2014, 11:14:43 PM12/2/14
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1163878:
> On Tue, Dec 2, 2014 at 7:29 PM, Dmoneyzzz Darko <li...@ruby-forum.com>
> wrote:
>
>> undefined method `merge' for #<Array:0x5c68788> in
>> appointments/_form.html.erb
>
> OK, good, but --
>
>>> How did your code compare to the documentation for that method?
>
>> <%= f.select "appointment_time", "test", timeslots.map.with_index{
>> |name, index| [name, name] } %>
>
> From the ActionView::Helpers::FormBuilder doc example:
>
> <%= f.select :person_id, { |p| [ p.name, p.id ] },
> include_blank: true %>
>
> How do those two method signatures differ? Hint: what does "test"
> in the first one represent?
>
> --
> Hassan Schroeder ------------------------ hassan.s...@gmail.com
> http://about.me/hassanschroeder
> twitter: @hassan

Thanks for walking with me.

Appears as though test is in the same location as Person.all.collect. if
I change test to something like appointment.all.collect I might get
another value..?

Hassan Schroeder

unread,
Dec 2, 2014, 11:33:49 PM12/2/14
to rubyonrails-talk
On Tue, Dec 2, 2014 at 8:13 PM, Dmoneyzzz Darko <li...@ruby-forum.com> wrote:

> Appears as though test is in the same location as Person.all.collect. if
> I change test to something like appointment.all.collect I might get
> another value..?

You might - easiest way to find out is try it :-)
Reply all
Reply to author
Forward
0 new messages