簡體   English   中英

Rails 4:改變設計路線

[英]Rails 4: Changing devise routes

我正在使用Devise 3.4.1並且我有一個模型誰屬於設計User (稱為resume 。而不是localhost:3000/resume/new我想改變它做localhost:3000/users/resume/new 。我嘗試過下列:

namespace :users do
    resources :resume, except: [:index]
  end

但它顯示:

ActionController::RoutingError at /user/resume/new
uninitialized constant User::ResumeController

控制器是以下代碼:

class ResumeController < ApplicationController

    before_action :find_resume, only: [:show, :edit, :update, :destroy]
    before_action :authenticate_user!, except: [:index, :show]

    def index
        @resumes = Resume.all
    end

    def show
    end

    def new
        @resume = current_user.resumes.build
    end

    def create
        @resume = current_user.resumes.build(resume_params)

        if @resume.save
            redirect_to @resume, notice: "resume was successfully created"
        else
            render 'new'
        end
    end

    def edit
    end

    def update
        if @resume.update(resume_params)
            redirect_to @resume, notice: "resume was successfully updated"
        else
            render 'edit'
        end
    end

    def destroy
        @resume.destroy
        redirect_to root_path
    end

    private

    def resume_params
        params.require(:resume).permit(:description, :skills, 
                                        jobs_attributes: [:id, :company_name, :location, :title, :duration, :description, :_destroy], 
                                        educations_attributes: [:id, :establishment, :Location, :majored, :duration, :description, :_destroy] )
    end

    def find_resume
        @resume = resume.find(params[:id])
    end
end

UPDATE

在User(routes.rb)中添加“s”后我得到了同樣的錯誤:這是我的路線:

在此輸入圖像描述

嘗試這個:

devise_scope :user do
  get 'resume/new' => 'resumes#new', as: 'new_resume'
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM