我有以下模型view
。以下控制器Admin::ViewsController
包含以下代码:
class Admin::ViewsController < ApplicationController
before_action :set_admin_view, only: [:show, :edit, :update, :destroy]
# GET /admin/views
# GET /admin/views.json
def index
@views = View.all
end
# GET /admin/views/1
# GET /admin/views/1.json
def show
filter_requests = FilterRequests.new(params)
@requests = filter_requests.determine_what_to_do
respond_to do |format|
format.js
format.html
end
end
# GET /admin/views/new
def new
@view = View.new
end
# GET /admin/views/1/edit
def edit
end
# POST /admin/views
# POST /admin/views.json
def create
@view = View.new(admin_view_params)
respond_to do |format|
if @view.save
format.html { redirect_to @view, notice: 'View was successfully created.' }
format.json { render action: 'show', status: :created, location: @view }
else
format.html { render action: 'new' }
format.json { render json: @view.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /admin/views/1
# PATCH/PUT /admin/views/1.json
def update
respond_to do |format|
if @view.update(admin_view_params)
format.html { redirect_to @view, notice: 'View was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @view.errors, status: :unprocessable_entity }
end
end
end
# DELETE /admin/views/1
# DELETE /admin/views/1.json
def destroy
@view.destroy
respond_to do |format|
format.html { redirect_to admin_views_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_admin_view
@view = View.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def admin_view_params
params[:admin_view]
end
end
uninitialized constant Admin::ViewsController::View
是我在set_admin_view
代码中遇到的错误。这是以下路线:
namespace :admin do
scope :requests do
resources :views
end
end
为什么我会遇到这个问题?
答案 0 :(得分:0)
如果你的viewmodel没有命名空间trip>
@view = ::View.find(params[:id])