[英]Redirecting to edit_profile after devise sign up
通過edit_profile_path
注冊后,我試圖使我的rails應用程序重定向到edit_profile_path
,但是在嘗試制定方法時遇到了嚴重的問題。 我在這里花了四個小時的時間來嘗試找到解決方案,但似乎找不到問題。
我當前的routes.rb:
resources :users, :only => [:index] do
member do
get :favourite_users, :favourited_users
end
resources :posts
resources :profiles, only: [:show, :edit]
end
我的RegistrationsController.rb
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
edit_profile_path(resource)
end
end
我的個人資料/edit.html.erb:
class User < ActiveRecord::Base
before_create :build_profile #creates profile at user registration
has_one :profile, dependent: :destroy
accepts_nested_attributes_for :profile
end
我的個人資料
class Profile < ActiveRecord::Base
belongs_to :user
def name
first_name + " " + last_name[0]
end
end
我的ProfilesController.rb
class ProfilesController < ApplicationController
def new
@profile = Profile.new
end
def show
end
def profile
end
def edit
@profile = current_user.profile
end
end
我已經嘗試了盡可能多的解決方案,但似乎只能得到:
undefined method `profile_path' for #<#<Class:0xb50b8618>:0xb50abe54>
或者,如果我從RegistrationsController中的edit_profile_path(resource)中刪除了(資源):
No route matches {:action=>"edit", :controller=>"profiles"} missing required keys: [:id]
任何幫助將不勝感激!
您是否嘗試過從控制台運行以下內容:
rake routes
這將輸出您的應用程序知道的所有路由。 我希望我能正確閱讀您的路由文件(如果不進行格式化,很難查看),但是由於它是嵌套路由,我想您實際上是想使用
edit_user_profile_path(resource)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.