rubymonolith / superform

Build highly customizable forms in Rails
MIT License
263 stars 14 forks source link

render field with a block leads to ArgumentError #39

Open goldelehr opened 3 weeks ago

goldelehr commented 3 weeks ago

Hello,

when running the example code from the README's Form Field Guide i get an ArgumentError upon reaching this block:

render field(:reason) do |f|
  div do
    f.label { "Why should we care about you?" }
    f.textarea(row: 3, col: 80)
  end
end

i get this error: ArgumentError #<Superform::Rails::Form::Field:0x00007f849562e168 @key=:reason, .... > (is not an ActiveModel-compatible object. It must implement :to_partial_path.)

I'm renderung the form with render SignupForm.new @user

with @user being an ActiveRecord backed entity.

Is there something wrong with how i call the form?

Thanks for your help

ediathome commented 3 weeks ago

Hi goldelehr, does your ActiveRecord model for your @user object have a field reason: Probably not and my guess is that this is causing the error… So add a :reason datafield to your AR model and it should work.

goldelehr commented 2 weeks ago

Hi ediathome,

Yes, my application has a user object that contains a 'reason' field. The issue arises when ActionView::AbstractRenderer::ObjectRendering attempts to access the to_partial_path method on an ApplicationForm::Field object, which does not exist for these specific objects. However, it does exist for the underlying user object.