0

Cheers! I have in routes code like this:

 user_photo GET    /users/:user_id/photos/:id(.:format)      photos#show

And I have a link_to helper:

= link_to 'Show', ...

How can I link it to show photo uploaded by current user?

user_photo_path

doesn't work

xamenrax
  • 1,724
  • 3
  • 27
  • 47

2 Answers2

1
link_to 'Show', user_photo_path(@user, @photo)

(This is assuming you have the @user and @photo objects available to you in your view - set these in your controller)

For more see http://guides.rubyonrails.org/routing.html#creating-paths-and-urls-from-objects

edralph
  • 1,831
  • 1
  • 14
  • 14
  • Changed to smth like this: `= link_to 'Show', user_photo_path(current_user, photo)` Because there was |photo| iterator, thank you! – xamenrax Dec 24 '12 at 09:19
  • Good - glad it worked. Should use the path helpers where possible otherwise it gets messy quickly. – edralph Dec 24 '12 at 09:24
1

Try this:

We can specify our own path.

<%= link_to "show", "/users/"+user_id.to_s+"/photos/"+id.to_s %>
suresh gopal
  • 3,138
  • 6
  • 27
  • 58