Link_To
Firstly, you shouldn't be trying to populate a "naked" <a>
with your ruby variable - you need to use the <%= link_to %>
helper:
<%= link_to photo.title, photo_path(photo) %>
The problem is your scope, especially considering this scope is used to determine a variable. I believe the issue is that since Rails expects a variable from this scope, it will not be able to process any of the links without having it
The simple way to resolve that error, as mentioned in the comments,is to populate the route with both values:
<%= link_to photo.title, photo_path(profile_name, photo) %> #-> photo & profile_name need to be declared
You'll want to look up a rake routes to make this work
Friendly_ID
If you want to populate the friendly_id
slug
values for this route, you'll need to do two things:
- Pass the
profile_name
value as a "slug" (not ID)
- Pass the
photo
object itself
I noticed in the comments, Tiago Farias
posted a possible solution for you. If you want that to work with friendly_id
, you'll need to pass the photo
object without defining the id
attribute (this will let friendly_id
work its magic)
The next thing you need to consider is that since :profile_name
is not tied to any "resource" (controller / model), friendly_id
won't be able to populate the name / value that you'd expect. In this case, you need to set the value yourself (by defining it explicitly in your controller)