rails控制器操作未正确执行

时间:2015-11-03 19:12:57

标签: ruby-on-rails ruby

我正在尝试构建我的第一个rails应用程序,但在添加身份验证之后 我的控制器出了问题。 我使用rails scaffold命令来实现我的Tutor模型。添加身份验证后,我无法编辑和更新我的导师,也无法查看导师详细信息。 我收到以下错误消息'未知操作 - 操作' 2'无法找到TutorsController' 有什么想法或帮助吗? 在下面找我的Tutor控制器。谢谢

ArrayList searched = new ArrayList(
             seats.Where(c => c.Section == section && !string.IsNullOrEmpty(section))
                  .Where(c => c.Row == row && !string.IsNullOrEmpty(row))
                  .Where(c => c.id == id && !string.IsNullOrEmpty(id)).ToList());

我正在添加我的路由:

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

1 个答案:

答案 0 :(得分:1)

你想摆脱这一行:

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

不清楚它为什么存在,但它匹配的是先前路线没有发现的任何东西。这意味着该行以下的任何内容都永远不会匹配。

来自the docs

  

Rails路由按照指定的顺序进行匹配,因此如果您有资源:照片上方的照片/投票&#39;资源行的show action的路由将在get行之前匹配。要解决此问题,请将获取行移到资源行上方,以便首先匹配。