sferik/rails_admin — Issue #958: Default values for nested models
Author: dunyakirkali
Created: 2012-02-03 16:37:57+00:00
State: open

Hello community,

I can't seem to get default values working with nested models. Let me be more clear.
I have:

Note Model

```ruby
belongs_to :user, :inverse_of => :notes
```

User Model

```ruby
has_many :notes, :inverse_of => :user
```

RailsAdmin Configuration

```ruby
config.model Note do
edit do
field :user do
default_value do
bindings[:view]._current_user
end
end
end
```

I have experimented with the following variations:
1- This works but displays integers instead of the model name

```ruby
config.model Note do
edit do
field :user_id do
default_value do
bindings[:view]._current_user.id
end
end
end
```

2- This does not set any default value

```ruby
config.model Note do
edit do
field :user_id do
default_value do
bindings[:view]._current_user
end
end
end
```

3- I also tried using enumerations instead of the default multi select but that didn't help either.

Any suggestions would be appreciated.
Thanks.