User profile won't display for current user

14 views
Skip to first unread message

Ruth Stephenson

unread,
Jul 3, 2016, 1:11:23 PM7/3/16
to rubyonra...@googlegroups.com
Hi, I've added a user (devise) and a profile to my app. The problem is
that I can't display the profile for that user. It tells me that there
is No route matches [GET] "/profile/1"

I wonder if anyone can point out where I'm going wrong, and why?

routes.rb
Rails.application.routes.draw do
devise_for :users
resources :profiles
resources :appointments

root 'page#home'
get 'page/testimonials'
get '/signedinuserprofile' => 'profiles#signedinuserprofile'
#get 'page/home'

profiles controller:
class ProfilesController < ApplicationController
before_action :set_profile, only: [:show, :edit, :update, :destroy]


# GET /profiles
# GET /profiles.json
def index
@profiles = Profile.all
end

def signedinuserprofile
profile = Profile.find_by_user_id(current_user.id)
if profile.nil?
redirect_to "/profile/new"
else
@profile = Profile.find_by_user_id(current_user.id)
redirect_to "/profile/#{@profile.id}"
end
end

application controller:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def after_sign_in_path_for(resource)
"/signedinuserprofile"
end
end

sessions controller:
class SessionsController < Devise::SessionsController
#after_sign_in_path_for is called by devise
def after_sign_in_path_for(user)
"/signedinuserprofile" # here I provide the path for the user's
profile
end
end

--
Posted via http://www.ruby-forum.com/.

macs...@gmail.com

unread,
Jul 4, 2016, 10:35:28 AM7/4/16
to Ruby on Rails: Talk
I think you would use GET /users/profile/1

Reply all
Reply to author
Forward
0 new messages