Undefined Local variable or `f 'method In partial view

It seems like such a stupid and easy solution (maybe it is), but I have not searched for SO and other areas on the Internet. I get undefined method local variable error 'f'within my partial use in my opinion. I assume that the “blocking block” ends somehow before reaching partial, but I'm not 100% sure.

Thanks in advance for any help. I am currently learning Rails so naked with me if this is a very simple fix.

Partial

<% if user_admin_or_premium? %>
  <div class="form-group">
    <%= f.label :private, class: 'checkbox' do %>
      <%= f.check_box :private, :true %> Private Wiki?
    <% end %>
  </div>
<% end %>

View

<div class="col-md-8">
  <%= form_for @wiki do |f| %>
    <div class="form-group">
      <%= f.label :title %>
      <%= f.text_field :title, class: 'form-control', placeholder: "Enter Wiki Title" %>
    </div>
    <div class="form-group">
      <%= f.label :body %>
      <%= f.text_area :body, rows: 10, class: 'form-control', placeholder: "Enter Wiki Body" %>
    </div>
    <%= render "wikis/form", f: f  %>
    <div class="form-group">
      <%= f.submit "Save", class: 'btn btn-success' %>
    </div>
  <% end %>
</div>

Complete mistake

NameError in Wikis#new

undefined local variable or method `f'

<% if user_admin_or_premium? %>
  <div class="form-group">
    <%= f.label :private, class: 'checkbox' do %>
      <%= f.check_box :private, :true %> Private Wiki?
    <% end %>
  </div>
+4
source share
1 answer

Omit the key partial:to the render function:

<%= render "wikis/form", f: f %>

, , , , . :

<%= render partial: "wikis/form", locals: { f: f } %>

+10

All Articles