Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3嵌套资源视图(索引)_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails Rails 3嵌套资源视图(索引)

Ruby on rails Rails 3嵌套资源视图(索引),ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,因此,我最终使用嵌套资源使我的URL正常工作,但仍然存在一个小问题。我的mysite.com/profile/1/photos/new页面和表单工作正常,但mysite.com/profile/1/photos页面不工作。我不知道这是为什么 我的嵌套路由看起来是这样的 resources :profiles do resources :photos end 索引页将不工作,它给我以下错误 undefined method `user_id' 这是我的photos_controller.rb

因此,我最终使用嵌套资源使我的URL正常工作,但仍然存在一个小问题。我的mysite.com/profile/1/photos/new页面和表单工作正常,但mysite.com/profile/1/photos页面不工作。我不知道这是为什么

我的嵌套路由看起来是这样的

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>

使用者
标题
描述
“你确定吗?”,:method=>:delete%>

mysite.com/photos
应该是
mysite.com/profiles/:profile\u id/photos
photos/edit
应该是
profiles/:profile\u id/photo/:id/edit

链接帮助程序看起来像

link_to "Photos", profile_photos_path(@profile)
link_to "Edit photo", profile_edit_photo_path(@profile,@photo)
查看rails指南关于