Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude attributes from rails_admin

I try to use rails_admin with strong_parameters and awesome_nested_set.

Probably because of awesome nested sets some attributes like Lft and Rgt show up in the rails_admin edit view of the respective model (category) and are editable. Once I change eg the name of the attribute and hit the save button I get the following error message:

Unauthorized assignment to lft: it's an internal field handled by acts_as_nested_set 
code, use move_to_* methods instead.

In an older version of my app I could just remove lft and rgt from the attr_accessible list (I don't want to manually edit them) but with strong_parameters this seems not to be possible.

Is there any war I can exclude certain attributes to be editable through rails_admin?

like image 677
Twiek Avatar asked Aug 04 '26 17:08

Twiek


1 Answers

I met the same error in the Rails 4 app (with acts_nested_set and rails_admin):

ActiveRecord::ActiveRecordError - Unauthorized assignment to lft: it's an internal field handled by acts_as_nested_set code, use move_to_* methods instead.:
  awesome_nested_set (3.0.0.rc.3) lib/awesome_nested_set/awesome_nested_set.rb:127:in `lft='
  ...

This trouble appeared, because few fields was accessible in rails_admin. So, i just excluded them:

  rails_admin do
    navigation_icon 'icon-phone'

    edit do
      exclude_fields :id, :lft, :rgt, :children, :depth
    end
  end

And that was all.

like image 66
ExiRe Avatar answered Aug 07 '26 06:08

ExiRe