I have a resource called NonprofitRequest (users c...
# avo-2
f
I have a resource called NonprofitRequest (users can request nonprofits missing from our system). In the admin, I'd like to have an action AcceptNonprofitRequest, which accepts a request by creating a Nonprofit with the requested values (name, location, website, etc). Ideally, in the AcceptNonprofitRequest action, the admin user will be able to modify the requested values before submitting though. Essentially, I'd like to be able to have the
default
value of the action fields use the values from the NonprofitRequest model. Like this:
Copy code
ruby
class AcceptNonprofitRequest < Avo::BaseAction
  field :name, as: :text, default: ->(model) { model.name }
end
As far as I can tell the above is not possible. Anyone have any other ideas on how I can enable this behavior on an action? Maybe I need to use something besides actions for this?
l
Are you sure that doesn’t work?
Have you tried default: -> {mode.name} ?
*sorry for the lack of formatting. I’m AFK
the model is available when you run the action from the Show view of a record, not from the Index view
That’s because the user can select multiple records
f
Maybe it only works on
new
then, reading the docs there - Now I'm just trying
Copy code
ruby
field :foo, as: :text, required: true, default: -> { 'bar' }
and I'm getting:
on the
show
view
l
The default option works only on the new view
Are you sure this is on the show ciew? That looks like a field on edit.
f
Oh hmm it's actually a form in an action, opened from the show view. Does that count as an edit view for the action form?
l
it seems like default as a proc is not supported in an action. I'm getting the same result
creating a GH issue
2 Views