Reputation: 6403
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>
Upvotes: 2
Views: 668
Reputation: 7046
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
Upvotes: 1