Reputation: 576
I have a model called LetterResponse
belongs_to :user
LetterResponse have following field (just shortening my model)
:id
:title
:user_id
while admin creates new letter_response he will fill the title and when he types user name it should autofill
I have 100k users so can't do
f.input :response_user_id, :as => :select, :collection =>
User.all.collect {|user| [user.first_name, user.user_id] }, label: "Parent"
even choozen-rails gem does same pre loads data.
so tried with activeadmin-addons ajax-search by following
https://github.com/platanus/activeadmin_addons/blob/master/docs/select2_search.md
f.input :response_user_id, as: :search_select, url: admin_users_path,
fields: [:user_last_name], display_name: 'name',
minimum_input_length: 2
but I get an error:
undefined method response_user
How to proceed?
Upvotes: 0
Views: 2591
Reputation: 11
Shouldn't your input field be :user_id instead of :response_user_id, (becuase you mention your LetterResponse has a belongs_to :user relation (not belongs_to :response_user.
So, it should look like
f.input :user_id, as: :search_select, url: admin_users_path, fields: [:user_last_name], display_name: 'name', minimum_input_length: 2
Upvotes: 1