Reputation: 51
I want a make view "_error_messages".But browser show me error
undefined local variable or method `event'
This is my partial _error_messages:
<% if event.errors.any? %>
<div id="errorExplanation">
<h2> В форме обнаружено <%= pluralize(event.errors.count, "ошибка", "ошибки") %>:</h2>
<ul>
<% event.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
this is my partial _event_form:
<%= form_for event, html: { class: "event-form" } do |f| %>
<%= render 'shared/error_messages' %>
<% unless current_user %>
<div class='row'>
<div class='col-md-4'>
<div class="form-group col-sm-12">
<%= label :email, "Введите Ваш email:" %>
<%= text_field_tag :email, "",class: "form-control" %>
<small>Он нужен для того, что бы Вы могли позже отредактировать добавленное Вами событие.</small>
</div>
</div>
</div>
<% end %>
Upvotes: 1
Views: 482
Reputation: 13736
Have you tried explicitly passing event to the partial?
Like this:
<%= render 'shared/error_messages', event: event %>
Or this:
<%= render partial: 'shared/error_messages', locals: { event: event } %>
If the error isn't on the partial but in the view itself, check if you're not missing a @
before the events variable or if it should be a method.
Upvotes: 1