updating records

I know how to update records, but not sure where I should put my code when product qty == 0.

I do have a flash notice on the show page that displays a message when the last item is left.

Should I put update the records on the show page as well ? (when qty == 0 )

Thanks,

Joe

I know how to update records, but not sure where I should put my code when product qty == 0. I do have a flash notice on the show page that displays a message when the last item is left.

Should I put update the records on the show page as well ? (when qty == 0 )

Your question is difficult to understand given that we have no knowledge of your application other than the text above. Why do you need to update any records if the the quantity is already 0?

Colin

ok, well I need to flip a few boolean values to begin the group order process.

Oh, you mean that when the amount goes to zero you need to take some action? In that case that should probably be initiated by the action that sets it zero, either directly on updating it to zero or possibly in an after filter. Or have a background job that looks for zero and takes the appropriate action.

Colin

Ok, since it’s on the show page I can check for that (and it did work on that page), but as soon as it is added I think I need to redirect to another page,

(because I don’t display items that are fully funded and i got a page not found message 404)… I’ll try it soon. Some sort of congratulations page - “we have met the target , blah blah blah…”

Thanks,

Joe

Ok, since it's on the show page I can check for that (and it did work on that page), but as soon as it is added I think I need to redirect to another page,

You shouldn't be doing it in a view at all, you should do it in the action or model that updates the quantity, when it sees it is zero.

Colin

Yes, in the product controller?

In

Def show

End

Yes, in the product controller?

In Def show End

That is not a page that is a controller action, which invokes a view. It is important to use the correct words or others will not know what you mean. By page I assumed you meant the view. But surely you are not changing the quantity in that action, I would have expected a change in quantity to be in an Update action.

Colin

ok, so I got it working…

the process is add to cart … my show page updates quantity… and if it reached 0 now i’ve got it updating and redirecting to root_path.

works like a charm. (not sure if that’s optimal).

I’ve got to fix my default scope.

I've got to fix my default scope.

Default scopes are a serious anti-pattern, and cause more pain than they solve. I cannot think of one time I used them that I didn't regret it later.

Walter

Yes, I know.

I learned about using the default scope, then put it into my app. Then I discovered everyone said not to use them. lol.

Yes, I know.

I learned about using the default scope, then put it into my app. Then I discovered everyone said not to use them. lol.

Yes, default scope seems like a good idea initially, but it often end with tears :frowning:

Colin

Great, I’ve got my new scope in there. Seems to be working well.

I’ve got to learn how to write tests. :slight_smile: