Steve R. wrote:
This code implies that you are using a GET method to submit your data.
Even inside a form, a link_to will create an <a href … > link. Look at
your logs (log/development.log) and see what the params hash has in it
when the action is invoked (you are running tail -f log/development.log,
I suppose it is a get. I tried using a form instead just to see if it
would help, but I’m having trouble accessing variables from database in
the form. For instance, in _form.rhtml I have code that says:
<%= h(product.title) %>
But that simple code gives me an “undefined local variable or method
`product’ for #<#Class:0x4081f164:0x4081f0b0>” error
If I understand the original problem, you have a “meta-field” called
qty_added that is not a database column.
That’s correct. In my original model I had a line setting quantity
manually. i.e. item.quantity = 1. I want to change that to
item.quantity = qty_added but can’t seem to pass the variable to my
Its behavior is to exist solely
to add to the quantity column that is in the database. Rails won’t
automatically know what to do when that unknown field comes back in the
params hash, so you will have to manually extract it and stuff it in the
thingie = Thing.find(params[:id])
thingie.quantity += params[:product][‘qty_added’] # assuming you
wanted to add…
# take some corrective action.
I tried the above but got an undefined method quantity error. I then
tried adding attr_accessor to my models for both product.rb and
line_item.rb but that didn’t solve it. Couldn’t really figure out where
to define quantity to make it happy.
Alternatively, you can define the behavior in your model by adding
accessors for qty_added and making the write accessor add to quantity.
I would be happy to try this too… really I’m just looking for the
easiest solution. :ol
Does this help? Does anyone else have thoughts on this?
I’m starting to understand things better… I appreciate your help…
please keep throwing suggestions at me!!!