I have a Company and a User model, both with a slug via friendly_id. Slugs are ensured to be unique across both models.
I'd like to have URLs:
http://www.example.com/any_company_name
http://www.example.com/any_user_name
e.g. both /apple
and /tim
I'm not sure how to achieve this in Rails.
I have tried various permutations of:
routes.rb:
resources :users, path: ''
resources :companies, path: ''
get '*search', to: 'my_controller#redirect'
and
my_controller#redirect:
@company = Company.friendly.find(params[:search])
redirect_to @company if @company
@user = User.friendly.find(params[:search])
redirect_to @user if @user
However I can't get it to work. I can get /apple
to redirect to /companies/apple
and /tim
to redirect to /users/tim
(by removing the path: ''
option) but this is not what I want to achieve.