So I finally got my urls to work using nested resources but there’s still one little problem. I got the mysite.com/profile/1/photos/new page and form to work properly but the mysite.com/profile/1/photos page does not work. I am not sure why at this point.
My nested routes look like so.
resources :profiles do
resources :photos
end
The index page will not work, it gives me the following error
undefined method `user_id'
This is what I have in my photos_controller.rb file
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
Here is the index form. This form will not work.
<% 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>
mysite.com/photosshould bemysite.com/profiles/:profile_id/photosandphotos/editshould beprofiles/:profile_id/photo/:id/editlink helpers will looks like
Check out rails guides about nested resources