Update Action doesn't work for STI models #52

Closed
tkieft opened this Issue May 18, 2011 · 5 comments

Comments

Projects
None yet
3 participants
@tkieft

tkieft commented May 18, 2011

When you edit a model that implements single-table inheritance, the updates are not saved

@gregbell

This comment has been minimized.

Show comment Hide comment
@gregbell

gregbell May 18, 2011

Contributor

Thanks. We should definitely add STI models to the test suite to make sure we have everything working correctly.

Contributor

gregbell commented May 18, 2011

Thanks. We should definitely add STI models to the test suite to make sure we have everything working correctly.

@gregbell

This comment has been minimized.

Show comment Hide comment
@gregbell

gregbell May 26, 2011

Contributor

@tkleft We implemented some cukes to test STI and they all seem to pass. Could you please post the stacktrace and relevant code of the issue you had?

Contributor

gregbell commented May 26, 2011

@tkleft We implemented some cukes to test STI and they all seem to pass. Could you please post the stacktrace and relevant code of the issue you had?

@tkieft

This comment has been minimized.

Show comment Hide comment
@tkieft

tkieft May 27, 2011

I actually don't get an error....everything goes well, but the object is never updated.

I patched the update_resource action to do this to fix the problem:

controller do
def update_resource(object, attributes)
object.attributes = params[object.class.to_s.underscore]

  run_update_callbacks object do
    save_resource(object)
  end
end

end

Perhaps it could be fixed upstream too by passing the correct attributes into the function.

Are you able to repro this on your end?

On May 25, 2011, at 7:56 PM, gregbell wrote:

@tkleft We implemented some cukes to test STI and they all seem to pass. Could you please post the stacktrace and relevant code of the issue you had?

Reply to this email directly or view it on GitHub:
gregbell#52 (comment)

tkieft commented May 27, 2011

I actually don't get an error....everything goes well, but the object is never updated.

I patched the update_resource action to do this to fix the problem:

controller do
def update_resource(object, attributes)
object.attributes = params[object.class.to_s.underscore]

  run_update_callbacks object do
    save_resource(object)
  end
end

end

Perhaps it could be fixed upstream too by passing the correct attributes into the function.

Are you able to repro this on your end?

On May 25, 2011, at 7:56 PM, gregbell wrote:

@tkleft We implemented some cukes to test STI and they all seem to pass. Could you please post the stacktrace and relevant code of the issue you had?

Reply to this email directly or view it on GitHub:
gregbell#52 (comment)

@tkieft

This comment has been minimized.

Show comment Hide comment
@tkieft

tkieft May 27, 2011

Ah...just looked at your cuke. I think it doesn't cover the case I was using. Let me put what I was trying to accomplish in terms of your models: User and Publisher.

I only have "User" registered with ActiveAdmin, not "Publisher," and I was trying to update a "Publisher" by going to /admin/users/:id/edit, and then save the form. Does that make sense?

tkieft commented May 27, 2011

Ah...just looked at your cuke. I think it doesn't cover the case I was using. Let me put what I was trying to accomplish in terms of your models: User and Publisher.

I only have "User" registered with ActiveAdmin, not "Publisher," and I was trying to update a "Publisher" by going to /admin/users/:id/edit, and then save the form. Does that make sense?

@Hakon

This comment has been minimized.

Show comment Hide comment
@Hakon

Hakon Jun 25, 2011

say you have the models

    class ArticleCategory < Category; end;

and register the active admin panel like this:

when you update an instance of ArticleCategory the form sends an article_category => { :name => "test" } where active_admin expects category => { :name => "test" }.

you can fix this by adding :as => :category to the form.

        f.inputs :name
        f.buttons
    end

Hakon commented Jun 25, 2011

say you have the models

    class ArticleCategory < Category; end;

and register the active admin panel like this:

when you update an instance of ArticleCategory the form sends an article_category => { :name => "test" } where active_admin expects category => { :name => "test" }.

you can fix this by adding :as => :category to the form.

        f.inputs :name
        f.buttons
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment