Field is always read only when using HABTM #745

Closed
rudf0rd opened this Issue Sep 27, 2011 · 8 comments

2 participants

@rudf0rd

Hey guys, I posted over on the google groups and am hoping there might be some more eyes here.

Here's the thread: http://groups.google.com/group/rails_admin/browse_thread/thread/676de628d4a14246

Basically I can't get a HABTM association not to be read only no matter what I try to make attr_accessible. This also prevents it from rendering a partial I believe, as rails_admin is seeing it as read only and just giving me the dash. Any examples for the post attr_accessible changes that were made a while back?

@bbenezech
Collaborator

Does it work without attr_acessible?
The key you would need to white-list is :collection_singular_ids

@rudf0rd

Awesome. That was the key for like 90% of it. The one model it didn't work for was a polymorphic association. If it's an address model (aka addressable_id and addressable_type), what would I need to whitelist in the attr_accessible? For example:

has_one :address, :as => :addressable, :dependent => :destroy

So far I've tried :address, :addresses, :addressable_ids, :addressable_id, :addressable, :addressable_type, :address_id, :address_ids. Any ideas for that one?

@bbenezech
Collaborator

It should be :address_id
Anyway it's the name of the mass-assigned attribute. Check your params hash when you create/update (without :attr_accessible activated obviously, since RA will not render the non-assignable fields) and you'll get all the attributes you'll need to whitelist.

@rudf0rd

Ha.. check this out:

undefined method `addres_id' for #College:0x135224120

So I put attr_accessor :addres_id in there and it showed up.

@rudf0rd

Unfortunately, it's trying to send the wrong param and isn't able to successfully update. Any ideas? Like, can I force it to use a foreign key I specify?

@bbenezech
Collaborator

Ouch.

@bbenezech bbenezech added a commit that closed this issue Sep 28, 2011
@bbenezech bbenezech Fix #745 a311e3b
@bbenezech bbenezech closed this in a311e3b Sep 28, 2011
@rudf0rd

Tested and working now. Thanks Ben!

@bbenezech
Collaborator

You're welcome. Thanks for the bug hunting!

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