Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

8 digit random permalink and routing

Hi guys,

I'm building an app where people can save a record and come back to access it later, to avoid managing users and to keep it simple i wanted to make the permalink to the records be a random 8 digit code that they would need to bookmark.

using this base32 gem (https://github.com/levinalex/base32) I was able to have the system generate a random code on before_create then for my routes I changed my show link to use the bas32 field and also made some changes to my record_controller.rb file

recor_controller.rb

  • removed :show from the before_action
  • added a record.find_by_random_id(params[:random_id])

routes

get "/record/:random_id" => 'records#show', :as => "show_post"

Problem i'm having now is my edit and destroy links do not work. I think I need to make similar changes to the routes and links but not sure what to do I tried a lot of different things but so far what i'm getting is that my show link goes to record/8digitcode but edit link goes to records/8digitcode (record plural) and fails.

1 Answer

bump