P
P
Pianista2016-05-14 13:23:59
Ruby on Rails
Pianista, 2016-05-14 13:23:59

The voting form is not rendered. What to fix?

The essence of the application:
- there are lists
- each list has many items
- you can vote for each item
List page:
lists/show.html.erb

<%= render 'list_description' %>
<ol>
<%= render @list.items.order(rating: :desc) %>
</ol>

Item template:
items/_item.html.erb
<li>
<%= item.title %>
<%= render "votes/like" %> - Этот рендер формы голосования вызывает ошибку
</li>

Voting form:
votes/_like.html.erb
<%= form_for :vote, url: list_item_votes_path(:item_id => item, :list_id => @list.id) do |f| %>
<%= f.hidden_field :vot, value:'up' %>
<%= f.submit " ",class: "vote-button bth-like"  %>
<% end %>

<%= form_for :vote, url: list_item_votes_path(:item_id => item, :list_id => @list.id) do |f| %>
<%= f.hidden_field :vot, value:'down' %>
<%= f.submit " ",class: "vote-button bth-dislike"  %>
 <% end %>

If I insert this form not through rendering, but directly into the item template, then everything works.
If through rendering, it gives the following error:
undefined local variable or method `item'
Tell me what needs to be fixed to make the render work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Karim Kyatlottyavi, 2016-05-14
@Pianista

Try like this.
Local variables are usually not carried over between templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question