Search code examples
ruby-on-railsauthenticationslug

How to avoid showing :id in url when editing


i am using like

def to_param
"#{self.attr1}-#{self.attr2}"
end

and my urls look as I want to, though when I :edit,(editing) the url redirects/goes back to showing the :id.

Im letting guest users change some specific record without logging in sending them through a specific link and I want users to not be able to manually change the url or at least show them a large slug so they can't guess the id.

Thanks in advance for any help, theres many posts around this but can't find a solution to fit my needs.


Solution

  • credit to @Dipak for pointing me in the right direction.

    I managed to do it with Friendly_ID gem, though it gave me some trouble because i had some redirects before the actions and it didn't want to pick up the slugs.

    I had my redirects as 'redirect_to mymodel_path'

    I finally got it working passing 'redirect_to mymodel_path(mymodel)'

    Thanks!