I have an Artist model is name:string. and I want /users/1/artists/jimi-hendrix/posts instead of what I have now which is /users/1/artists/1/posts
The problem is I don't think I can use friendly_id for the artist's name, this is because I have multiples of the same artist name but I want to use the same slug, such as jimi-hendrix for all 'jimi hendrix' entries. Example:
/users/3/artists/jimi-hendrix/posts
/users/55/artists/jimi-hendrix/posts
/users/106/artists/jimi-hendrix/posts
Friendly_id makes it looks like this: (which I can't have) /users/3/artists/jimi-hendrix/posts /users/55/artists/jimi-hendrix--2/posts /users/106/artists/jimi-hendrix--3/posts
So what I'm thinking of doing is passing that artist name parameter to the controller instead of the id. But I need to take the name and replace all whitespace with "-" and then add back the whitespace in the controller correct?
This woulds be my link: (can you doing something like artist.name.gsub!() ??)
<% @artists.each do |artist| %>
<%= link_to artist.name, user_artist_posts_path(@user, artist.name) %>
<% end %>
Then reverse it when I get the code back to the controller?
def index @name = params(:artist_id).gsub() # ? @posts = ... .... end
Or would anyone know how to have non-unique slugs in friendly_id, so it doesn't append the --2, --3 if the attribute has a duplicate name?