views:

30

answers:

2

I have two models here: Package and Status

Package belongs_to status

Status has_many packages

So, my Package model has a status_id column

In my Packages controller, I've got this method (that receives data from an ajax POST call):

def edit_status
  @status = Status.find_by_name(params[:status])
  Package.update(params[:id], :status_id => @status.id)
end

But it's weird...I can't get status_id to update to save my life. If I change out the status_id column for any other column in the record (such as from_name) then it works fine.

I feel like I'm taking crazy pills here, but any ideas why this might not be working?

A: 

There may be a validation problem. I would do a "find" then "update_attributes", which will return "false", letting you know if the record is invalid.

Tim
I've actually tried doing that very thing and I get the exact same outcome.
Shpigford
A: 

You may need this in the Package Model:

accepts_nested_attributes_for :status, :allow_destroy => true

More information here: http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

Nick