0
所以我最终得到我的网址使用嵌套的资源,但仍然有一个小问题。我得到了mysite.com/profile/1/photos/new页面并且表单正常工作,但mysite.com/profile/1/photos页面不起作用。我不知道为什么在这一点上。Rails 3嵌套的资源查看(索引)
我的嵌套路线看起来像这样。
resources :profiles do
resources :photos
end
索引页面将无法正常工作,它给了我下面的错误
undefined method `user_id'
这是我在我的photos_controller.rb文件
def index
@profile = Profile.find(params[:profile_id])
@photo = Photo.find_by_id(params[:all])
end
def show
@profile = Profile.find(params[:profile_id])
@photo = Photo.find(params[:id])
end
这里是指数形式。此表单不起作用。
<% title "Photos" %>
<table>
<tr>
<th>User</th>
<th>Title</th>
<th>Description</th>
</tr>
<% for photo in ([@photos, @profile]) %>
<tr>
<td><%= photo.user_id %></td>
<td><%= photo.title %></td>
<td><%= photo.description %></td>
<td><%= link_to "Show", profile_photo_path %></td>
<td><%= link_to "Edit", edit_profile_photo_path%></td>
<td><%= link_to "Destroy", profile_photo, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>