Ruby on rails rails中缺少用于渲染的部分
我创建了部分调用_topics_list.form.html.erb的代码Ruby on rails rails中缺少用于渲染的部分,ruby-on-rails,Ruby On Rails,我创建了部分调用_topics_list.form.html.erb的代码 <table class="list" cellspaceing="0"> <thead class="head_list"> <tr> <th class="column">Name</th> <th class="column">Description</th> </tr> </the
<table class="list" cellspaceing="0">
<thead class="head_list">
<tr>
<th class="column">Name</th>
<th class="column">Description</th>
</tr>
</thead>
<% @topics.each do |topic| %>
<tr class="row">
<td data-label="Name" class="column first"><%= topic.name %></td>
<td data-label="Description" class="column column_problem">
<%= link_to topic.description, topic_path(topic), class:"link_for_column_problem" %>
</td>
<td data-label="Date" class="column"><%= topic.created_at.strftime("%d %b, %Y") %></td>
</tr>
<% end %>
</table>
更新
<p id="notice"><%= notice %></p>
<h1 class="request_headline">All Topics</h1>
<%= render 'topics_list'%>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @topics.each do |topic| %>
<tr>
<td><%= link_to 'Show', topic %></td>
<td><%= link_to 'Edit', edit_topic_path(topic) %></td>
<td><%= link_to 'Destroy', topic, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Topic', new_topic_path %>
所有主题
我渲染部分的代码尝试更改
<p id="notice"><%= notice %></p>
<h1 class="request_headline">All Topics</h1>
<%= render 'topics_list'%>
所有主题
到
所有主题
另外,一个好主意是始终将局部变量传递给分部,而不是使用全局变量,这样您就可以绝对控制分部中的值。
然后部分使用
<table class="list" cellspaceing="0">
<thead class="head_list">
<tr>
<th class="column">Name</th>
<th class="column">Description</th>
</tr>
</thead>
<% topics.each do |topic| %>
<tr class="row">
.....
.....
</tr>
<% end %>
</table>
名称
描述
.....
.....
您的部分名称是\u topics\u list.form.html.erb
。要呈现此内容,您需要调用render'主题列表。表单'
,而不是render'主题列表'
您可以在尝试呈现topics/\u主题列表的位置共享代码吗?
是的,当然,已更新
<p id="notice"><%= notice %></p>
<h1 class="request_headline">All Topics</h1>
<%= render 'topics/topics_list' %>
<table class="list" cellspaceing="0">
<thead class="head_list">
<tr>
<th class="column">Name</th>
<th class="column">Description</th>
</tr>
</thead>
<% topics.each do |topic| %>
<tr class="row">
.....
.....
</tr>
<% end %>
</table>