2

In my Trailblazer cell I am rendering a fairly dynamic form. I'd like to do something like this:

concepts/card_form/views/_deck_form.erb*

<%= simple_form_for [parent,card] do |f| %>
   <div class='row'>
     <div class='col-md-6'>
       <%= render '_target_sentence', locals: { f: f } %>
     </div>

concepts/card_form/views/_target_sentence.erb

 <%= f.input :target_sentence_text,
        input_html: { class: 'target-sentence', value: card.target_sentence.sentence },
        label: "#{target_language} Sentence" %>

There's quite a bit more in the _target_sentence partial, but I've simplified it here. The problem is I can't pass the f form builder

The code above gives:

wrong number of arguments (given 2, expected 0..1)

Another variation:

<%= render '_target_sentence' %>

undefined local variable or method `f' for #<CardForm::Cell:0x007fc8eb7eaa48>

port5432
  • 5,889
  • 10
  • 60
  • 97

1 Answers1

1

I highly, highly recommend avoiding using partials when using Cells.

One of the main reasons to use Cells is to not use partials. What I would recommend instead is to create a Cell called TartgetSentence, that will take params, and create that "partial" view, then call this cell instead of the render "_target_sentece" you are doing.

Cells are ViewObjects, so you should treat them as objects. Define them once as many as you need and then construct your "master" cell and the corresponding view from these view objects, then call them when you need them. That's partially the reason they are faster than partials.

P.S.: You are also welcome to come over to our official Gitter channel for Trailblazer - you can get help there faster. https://gitter.im/trailblazer/chat

konung
  • 6,908
  • 6
  • 54
  • 79
  • Thank you @konung I did post on Gitter. I wanted a way to break up a complex form with some conditional logic on which fields appear ... but it doesn't seem possible to pass around form builders. I ended up going back to Rails partials. If there is a solution I'd be interested in hearing it. Cheers – port5432 Nov 03 '17 at 18:31