2015-11-03 103 views
1

我想構建我的第一個軌道應用程序,但添加了身份驗證後 我的控制器出現問題。 我用rails scaffold命令來實現我的Tutor模型。在我添加身份驗證後,我無法編輯和更新我的導師,也無法看到導師的詳細信息。 我收到以下錯誤消息'未知的行動 - 行動'2'找不到TutorsController' 任何想法或幫助? 請看下面我的導師controller.Thanks軌道控制器操作沒有正確執行

class TutorsController < ApplicationController 
before_action :confirm_logged_in 
before_action :set_tutor, only: [:show, :edit, :update, :destroy] 

# GET /tutors 
# GET /tutors.json 
def index 
@tutors = Tutor.all 
end 

# GET /tutors/1 
# GET /tutors/1.json 
def show 
end 

# GET /tutors/new 
def new 
@tutor = Tutor.new 
end 

# GET /tutors/1/edit 
def edit 
end 

# POST /tutors 
# POST /tutors.json 
def create 
@tutor = Tutor.new(tutor_params) 

respond_to do |format| 
    if @tutor.save 
    format.html { redirect_to @tutor, notice: 'Tutor was successfully created.' } 
    format.json { render :show, status: :created, location: @tutor } 
    else 
    format.html { render :new } 
    format.json { render json: @tutor.errors, status: :unprocessable_entity } 
    end 
    end 
end 

# PATCH/PUT /tutors/1 
# PATCH/PUT /tutors/1.json 
def update 
    respond_to do |format| 
    if @tutor.update(tutor_params) 
    format.html { redirect_to @tutor, notice: 'Tutor was successfully updated.' } 
    format.json { render :show, status: :ok, location: @tutor } 
    else 
    format.html { render :edit } 
    format.json { render json: @tutor.errors, status: :unprocessable_entity } 
    end 
end 
end 

# DELETE /tutors/1 
# DELETE /tutors/1.json 
def destroy 
@tutor.destroy 
respond_to do |format| 
    format.html { redirect_to tutors_url, notice: 'Tutor was successfully destroyed.' } 
    format.json { head :no_content } 
end 
end 

private 
# Use callbacks to share common setup or constraints between actions. 
def set_tutor 
    @tutor = Tutor.find(params[:id]) 
end 

# Never trust parameters from the scary internet, only allow the white list through. 
def tutor_params 
    params.require(:tutor).permit(:nome, :cognome, :email, :telefono) 
end 
end 

我加入我的路由:

Rails.application.routes.draw do 

    root 'access#login' 
    get 'home' => 'home#index' 
    get 'admin' => 'access#index' 
    get '/dashboard' => 'dashboard#index' 

    match ':controller(/:action(/:id))', :via => [:get,:post] 
    resources :disciplinas 
    resources :associaziones 
    resources :tutors 
    resources :bambinos 
end 
+2

你可以發佈你的'config/routes.rb'嗎?這很可能是你的路由問題。 – Brad

+0

我在 –

回答

1

你想擺脫這行:

match ':controller(/:action(/:id))', :via => [:get,:post] 

目前尚不清楚爲什麼它的存在,但它匹配了之前路線沒有采用的任何東西。這意味着該行下面的任何內容都不會匹配。

the docs

Rails的路線在他們指定的順序是匹配的,所以如果你有一個資源:一個get「照片/民意調查」節目行動對資源的線路路徑上面的照片會在獲得線之前匹配。要解決這個問題,請將資源行上方的獲取行移到第一行。

+0

之上添加了路由感謝不是很清楚,它的工作原理! –