Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- devise_for :users, path: '',
- path_names: {
- sign_up: '',
- registration: 'signup',
- sign_in: 'login',
- password: 'password',
- confirmation: 'verification'
- },
- controllers: {
- sessions: 'users/sessions',
- registrations: 'users/registrations',
- omniauth_callbacks: 'users/omniauth_callbacks',
- passwords: 'users/passwords'
- }
- resources :users, path: '', only: [:show] do
- member do
- get 'reviews', to: 'users#reviews', as: :reviews
- get :following, :followers
- post :follow, to: 'users#follow_user'
- post :unfollow, to: 'users#unfollow_user'
- end
- end
- resources :companies, path: '', only: [:show], as: :company do
- resources :products, path: '', only: [:show], as: :product
- end
- module Constraints
- class UserProfile
- def matches?(request)
- if request.path.include?('@')
- slug = request.path.delete('/@')
- User.where(slug: slug).exists?
- end
- end
- end
- end
- def set_user
- @user = User.includes(:reviews).find(params[:id].delete('@'))
- end
- # overwrite normalize function because it's stripping
- # out '@' when calling .parameterize
- def normalize_friendly_id(value)
- "@" + value.to_s.parameterize
- end
- User.each do |u|
- u.update_attribute(:slug, nil)
- end
- User.find_each(&:save)
- constraints(Constraints::UserProfile.new) do
- resources :users,
- ....
- end
- module Constraints
- class UserProfile
- def matches?(request)
- if request.path.match? //@(.*)/
- slug = request.path.split('/')[1]
- User.where(slug: slug).exists?
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement