WARNING
It's important to set the inverse_of as often as possible to your model's association attribute.
Has One
The HasOne association shows the unfolded view of your has_one association. It's like peaking on the Show view of that associated record. The user can also access the Attach and Detach buttons.
field :admin, as: :has_one
Options
-> searchable
Turns the attach field/modal from a select input to a searchable experience
class CourseLink < Avo::BaseResource
field :links,
as: :has_many,
searchable: true
endWARNING
Avo uses the search feature behind the scenes, so make sure the target resource has the search_query option configured.
# app/avo/resources/course_link_resource.rb
class CourseLinkResource < Avo::BaseResource
self.search_query = -> do
scope.ransack(id_eq: params[:q], link_cont: params[:q], m: "or").result(distinct: false)
end
endDefault
false
Possible values
true, false
-> attach_scope
Default
nil
Possible values
field :user,
as: :belongs_to,
attach_scope: -> { query.non_admins }Pass in a block where you attach scopes to the query object. The block is executed in the AssociationScopeHost, so follow the docs to see what variables you have access to.
Show on edit screens
By default, has_and_belongs_to_many is only visible on the Show page. If you want to enable it on the Edit page, too, you need to add the show_on: :edit option.
WARNING
Adding associations on the New screen is not currently supported. The association needs some information from the parent record that hasn't been created yet (because the user is on the New screen).
You may use the redirect helpers to have the following flow:
- User is on the
Newview. They can't see the association panels yet. - User creates the record.
- They get redirected to the
Show/Editview, where they can see the association panels. - User attaches associations.
Friendly.rb - Your friendly European Ruby Conference