Help with the Depot App

Do you have a list.rhtml file in views/ (name of your controller)?
Can you post some of the actual error message?

(By the way, if list is just a list then you probably don't need the :id => @local in the redirect, as it won't be used for anything. It doesn't hurt anything though.)

Yea thats not supposed to look like that actually...

def purchase
   @local = Product.find(params[:id])
   if @local.status.to_i == 0
     @local.status = 1
     flash[:notice] = 'Product Marked!'
     redirect_to :action => 'show', :id => @local
   elsif @local.status == 1
     flash[:notice] = 'Product Already Marked!'
     redirect_to :action => 'show', :id => @local
   end
end

Is status a string or an integer? If it's a string just do
if @local.status == "0"

The show method displays the individual product. If I click my purchase
button on the page.. it redirects and says 'Product Marked' but when I
look over in MySql.. the value didn't change.

Are you saving it?
Either a @local.save, or probably better is @local.update_attribute(:status, "1")

The advantage of the update_attribute is that it will only update that one column instead of rewriting the entire row.

Assuming status is a string, I'd write it like this:

  def purchase
    @local = Product.find(params[:id])
    if @local.status == "0"
      @local.update_attribute(:status, "1")
      flash[:notice] = 'Product Marked!'
    elsif @local.status == "1"
      flash[:notice] = 'Product Already Marked!'
    else
      flash[:notice] = "Status is #{@local.status} for some reason. This is not good."
    end
    redirect_to :action => 'show', :id => @local
end

If you changed to a String it sounds like status is empty or nil.

If status was an int, just remove the quotes from around the digits and it will work.

Put this in temporarily:

def purchase
@local = Product.find(params[:id])

if @local.status.blank?

flash[:notice] = "Status is nil"

elsif @local.status.empty?

flash[:notice] = “Status is an empty string”

elsif @local.status == “0”

@local.update_attribute(:status, “1”)
flash[:notice] = ‘Product Marked!’
elsif @local.status == “1”
flash[:notice] = ‘Product Already Marked!’
else
flash[:notice] = “Status is #{@local.status} for some reason. This is not good.”
end

redirect_to :action => ‘show’, :id => @local

end

Are you sure you're looking at the right record?

Change that notice to
flash[:notice] = "Status is nil for product #{@local.description}, id: #{@local.id.to_s}"

"description" may not be right, of course. Use whatever the column is for the product name.

FIXED!

Glad to hear it.

I feel really stupid though... I had:
class Product < ActiveRecord::Base

attr_accessor :status

I did the same thing once. I should have remembered.

when I needed...

attr_accessible :status

You don't need anything. Rails takes care of that for you. And as you've seen, adding the other kind hides the original.
And if you do use attr_accessible you hide any attributes you don't explicitly name.

http://railsmanual.com/class/ActiveRecord::Base/attr_accessible

...thanks for all the help.

My pleasure.