On 29 March 2010 21:44, Stephen None <[email protected]> wrote: > 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 -%> > <fieldset> > <legend>Process Return</legend> > <label>Barcode</label><%= text_field_tag 'barcode' %><br> > <label>Check Out?</label><%= check_box_tag 'checkout' %> > </fieldset> > <p> > <%= submit_tag "Update" %> > </p> > <% end -%>
As I said it is easier to use the form_for method. Just copy the existing edit view code (which presumably includes the barcode and checkout values) and remove from the form the fields that you do not want. The problem with the submit is that you are not putting the data in the params correctly. Try doing an edit and look in development.log to see what the params are, then do the same with yours and compare them. Your fields should be inside a hash for the complete object. But as I said if you use form_for it will all be done for you. I don't understand what problem you are having with form_for, what has it got to do with loading the edit page? You are using your new page instead of the edit page in this case. Colin > > > You have already seen my controller; there isn't much here so I must be > doing something pretty stupid... Thanks, > > Colin Law wrote: >> On 29 March 2010 19:00, Stephen None <[email protected]> wrote: >>> �def update >>> >>> � �...@barcode = params[:barcode] >>> � �...@checkout = params[:checkout] >>> >>> � �...@book = Book.find(:first, :conditions => {:barcode => [...@barcode]}) >>> >>> � �[email protected]_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 > > -- > 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 post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

