routes - ruby on rails myprofile page -
i want create profile page users signing let's user registered, profile link should be
website.com/profile/username and on views/profile/index.html.erb each user should see own profile , edit form_for guess
far have profiles_controller.rb, profile.rb model , resources :profilesfor routes.rb
best way that?
if wanna username need use slug. example below id version.
profile controller
def show @profile = profile.find(params[:id]) end routes:
get 'profile/:id' => 'profile#show' for :slug version, url this: http://localhost:3000/profiles/**username**
routes:
resources :profiles, param: :slug profiles_controller
def show end private def set_profile @profile = profile.find_by_username(params[:slug]) end or can use gem https://github.com/norman/friendly_id
Comments
Post a Comment