0
我有一個名爲「userinfo」的用戶配置文件控制器,它是相應的視圖。 userinfo索引是根路徑。在主頁(這是用戶信息索引),我有一個鏈接,可以將您帶到用戶個人資料頁面。它給我這個錯誤,當我去到主頁:爲什麼在嘗試訪問rails中的實例時遇到recordnotfound錯誤?
class UserinfosController < ApplicationController
before_action :find_userinfo, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
def index
@userinfors = Userinfo.find(params[:id])
end
def show
@myvideo = Video.last
end
def new
@userinformation = current_user.userinfos.build
end
def create
@userinformation = current_user.userinfos.build(userinfo_params)
if @userinformation.save
redirect_to root_path
else
render 'new'
end
end
def edit
end
def update
end
def destroy
@userinformation.destroy
redirect_to userinfo_path
end
private
def userinfo_params
params.require(:userinfo).permit(:name, :email, :college, :gpa, :major)
end
def find_userinfo
@userinformation = Userinfo.find(params[:id])
end
end
,我的看法是:
<%= link_to 'profile', userinfors_path(@userinfors) %>
我的路線。 rb文件:
Rails.application.routes.draw do
devise_for :users
resources :userinfos do
resources :videos
end
resources :pages
get '/application/decide' => 'application#decide'
root 'userinfos#index'
get '/userinfos/:id', to: 'userinfos#show', as: 'userinfors'
end
感謝您的任何幫助!
謝謝!我試圖使用快捷方式,因爲我不想在不同控制器之間創建關聯。但是,你的方式是有效的。 – Dinukaperera
你可以根據你的需要絕對地操作導軌,但是需要理解標準的方法..不管怎樣,很高興它有助於.. :) –