Hello,
I''m having a great time going through "Agile Wed Development with
Rails." The examples are *working perfectly*.
As a *learning exercise*, I''m trying to change the Depot Shipping web
page (book page 114, pdf page 123 in Aug 10 version) to show all of
the orders in the database with checkmarks next to those that have
already been marked as shipped as opposed to how it is defined in the
book -- which is *not* display the shipped orders at all.
It was easy to display both shipped and unshipped orders on the HTML page.
What I''m having a hard time getting my head around is how to display
to those order that have been marked as shipped with a *checked
checkbox* when the page is rendered.
>From the Depot example in the book on page 114:
<%= check_box("to_be_shipped", order_line.id, {}, "yes",
"no") %>
This appears to deviate from every other documented example of
check_box I can find (including those in the rails api docs -- all of
them show the second parameter as a string that names a method, *not a
number*). The other examples I''ve seen have a mapping between the
state of the checkbox and an model attribute in the database.
That''s not the case here. Here''s a description of the first
two
parameters from the same Agile book page:
"The first parameter is the name to be used for this field. The second
parameter is also used as part of the name, but in an interesting
way...In this example, the order id was 1, so Rails used the name
to_be_shipped[1]
for the checkbox."
The second parameter is *also part of the name*? I''m not sure I
understand what that means and I haven''t been able to find any other
documentation about this use.
Now, compare that to the rails documentation:
"check_box(object, method, options = {}, checked_value = "1",
unchecked_value = "0")
Returns a checkbox tag tailored for accessing a specified attribute
(identified by method) on an object assigned to the template
(identified by object). It''s intended that method returns an integer
and if that integer is above zero, then the checkbox is checked. "
The Agile book appears to use the second parameter as an index. That''s
even seems to be at odds with the book''s Rails reference definition
for check_box on page 354.
* So, the question for my first post to this list is two-fold:
1. How do I alter the check_box tag on page 123 to show
already-shipped items (those that have a "shipped_at" timestamp) as
check on the rendered HTML page?
2. Where can I find more documentation about using the second
parameter to check_box as an index?
Thank you in advance and I promise to contribute answers in the future. :-)
Scott