设计注册后重定向到edit_profile

时间:2014-06-10 23:24:34

标签: ruby-on-rails ruby-on-rails-4 devise routes

我试图让我的rails应用程序在通过设计注册后重定向到edit_profile_path,但是我在尝试解决问题时遇到了严重问题。我在这里花了四个小时试图寻找解决方案,但似乎无法找到问题。

我当前的路线.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

我的个人资料.rb

class Profile < ActiveRecord::Base

    belongs_to :user

    def name
        first_name + " " + last_name[0]
    end
end

我的个人资料控制器.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(资源)中删除(资源):

No route matches {:action=>"edit", :controller=>"profiles"} missing required keys: [:id]

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您是否尝试过从控制台运行以下内容:

rake routes

这将输出您的应用知道的所有路线。我希望我能正确阅读你的路线文件(很难看到没有格式化),但是它是一个嵌套的路线,我想你实际上想要使用

edit_user_profile_path(resource)
相关问题