我有一个名为博物馆的模型和另一个名为Exhibtion的模型。博物馆是展览的父母。
我已经创建了一个adhoc控制器来处理根页面。
路线档案:
get 'welcome/index'
resources :museums
resources :museums do
resources :exhibitions do
resources :exhibitionimages
end
resources :museumimages
end
root 'welcome#index'
(请忽略博物馆图像和exhitionimages模型)
我试图在根页上显示所有展览,作为一个包含展示,编辑,...的链接的表格。
这是欢迎控制器
class WelcomeController < ApplicationController
def index
@exhibitions = Exhibition.all
end
end
和viewfile index.erb:
<h1>Hello, Rails!</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th>Start</th>
<th>End</th>
<th>Link</th>
<th>Price</th>
</tr>
<% @exhibitions.each do |exhibition| %>
<tr>
<td><%= exhibition.title %></td>
<td><%= exhibition.text %></td>
<td><%= exhibition.start %></td>
<td><%= exhibition.end %></td>
<td><%= exhibition.linktoexhibition %></td>
<td><%= exhibition.price %></td>
<td><%= link_to 'Show', museum_exhibition_path(exhibition.museum, exhibition), method: :get %></td>
<td><%= link_to 'Edit', edit_museum_exhibition_path(exhibition.museum, exhibition), method: :get %></td>
<td><%= button_to 'destroy', museum_exhibition_path(exhibition.museum, exhibition), method: :delete %></td>
</tr>
虽然我的链接出错了。
似乎museum_id没有传递给表格link_to帮助者,因为它显示为&#39; NIL&#39;并且链接创建失败。 这些链接在博物馆控制器内部使用时非常有效(在同一桌子上展示了属于父母的展览)