Hmm, I understand what you are saying, and that is indeed what I tried
to do originally but because I am not loading the edit page first I am
pretty sure I cannot use the form_for method. The form_tag that I am
using appears to parse the fields correctly however the data is not
being processed correctly on the backend…
Parameters: {“commit”=>“Update”, “action”=>“update”,
“barcode”=>“123456789”, “checkout”=>“1”, “controller”=>“books”}
I am able to type the barcode in and hit update but I am being taken to
the update page rather than just processing the update method. I know
it is reading the hash correctly because if I change the barcode I am
getting a nil value error. Like you said, my form is simple (this is in
my index.erb.html file),
<% form_tag(:action => “update”) do -%>
Process Return
Barcode<%= text_field_tag 'barcode' %>
Check Out?<%= check_box_tag 'checkout' %>
<%= submit_tag "Update" %>
<% end -%>
You have already seen my controller; there isn’t much here so I must be
doing something pretty stupid… Thanks,
Colin L. wrote:
On 29 March 2010 19:00, Stephen N. [email protected] wrote:
�def update
� �@barcode = params[:barcode]
� �@checkout = params[:checkout]
� �@book = Book.find(:first, :conditions => {:barcode => [@barcode]})
� �@book.update_attributes(params[:book])
�end
Just use the same technique as on the edit page but miss out the
fields that you do not wish to change. Then submit to the existing
update action, you do not need to change it as update_attributes only
changes the fields that are provided, and leaves the others unchanged
(I think that is correct, someone will correct me if I am wrong).
Depending on how similar the required view is to the normal edit view
you may even be able to use the same one, just hiding the fields you
do not want.
By the way form_for is the conventional way now, rather than form_tag.
Your edit view will likely be using that unless you picked up the
code from an old tutorial or book.
Colin