0
在開始之前,讓我說我有兩個不同的設計用戶模型。如何將設計用戶連接到ProfilesController Ruby on Rails 4
我開始從scaffold_controller中刪除不必要的方法,因爲devise處理某些操作。
我試圖路由到current_user配置文件頁面,但每次嘗試在我的導航欄中添加鏈接時都會收到錯誤<%='我的配置文件',current_user%>在這種情況下不起作用。我計劃在完成連接這些控制器後立即建立關聯。
class ProfilesController < ApplicationController
before_action :set_profile, only: [:show, :edit, :update, :destroy]
# GET /profiles
# GET /profiles.json
def index
@profiles = Profile.all
end
# GET /profiles/1
# GET /profiles/1.json
def show
@user = User.find(params[:id])
respond_to do |format|
format.html
format.json {render :json => @user }
end
end
# GET /profiles/1/edit
def edit
end
# PATCH/PUT /profiles/1
# PATCH/PUT /profiles/1.json
def update
respond_to do |format|
if @profile.update(profile_params)
format.html { redirect_to @profile, notice: 'Profile was successfully updated.' }
format.json { render :show, status: :ok, location: @profile }
else
format.html { render :edit }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
# DELETE /profiles/1
# DELETE /profiles/1.json
def destroy
@profile.destroy
respond_to do |format|
format.html { redirect_to profiles_url, notice: 'Profile was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_profile
@profile = Profile.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def profile_params
params[:profile]
end
end
profiles GET /profiles(.:format) profiles#index
POST /profiles(.:format) profiles#create
new_profile GET /profiles/new(.:format) profiles#new
edit_profile GET /profiles/:id/edit(.:format) profiles#edit
profile GET /profiles/:id(.:format) profiles#show
PATCH /profiles/:id(.:format) profiles#update
PUT /profiles/:id(.:format) profiles#update
DELETE /profiles/:id(.:format) profiles#destroy
我會盡快嘗試此解決方案,並向您彙報。 – user3646743
我要做的是擦除配置文件控制器並向用戶控制器添加一個show操作。希望我能從這個角度開展工作。這似乎是一個過於複雜的方法。 – user3646743