用户个人资料不会显示当前用户

时间:2016-07-03 17:10:52

标签: ruby-on-rails

我在设计方面遇到了一些问题。我已经在我的应用中添加了一个用户表(设计),一个约会表和一个配置文件表。一个用户应该有很多约会,并且有一个配置文件。

问题是我无法显示该用户的个人资料。它告诉我没有路线匹配[GET]" / profile / 1"

我想知道是否有人可以指出我哪里出错,为什么?

的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'

个人资料控制器:

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

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

应用程序控制器:

class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

def after_sign_in_path_for(resource)
  "/signedinuserprofile"
end
end

会话控制器:

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 

1 个答案:

答案 0 :(得分:0)

您尝试使用资源丰富的路线但尚未在控制器中执行显示操作。添加show动作并从params @ profile.id

中查找用户

您实际上是重定向到您在配置文件控制器中没有的操作。

相关问题