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/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/096d35727c5c9f47b90e2df5a7c266d6%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment