0

我正在尝试将我的一个控制器(Testo)移动到管理空间,我已更改为路由文件,如下所示:

namespace :admin do
  resources :testos
end

控制器的类名:

class TestosController < ApplicationController

我得到的错误:

uninitialized constant Admin::TestosController

耙路线给了我:

        root        /                                Pages#index
    admin_testos GET    /admin/testos(.:format)          admin/testos#index
             POST   /admin/testos(.:format)          admin/testos#create
 new_admin_testo GET    /admin/testos/new(.:format)      admin/testos#new
edit_admin_testo GET    /admin/testos/:id/edit(.:format) admin/testos#edit
     admin_testo GET    /admin/testos/:id(.:format)      admin/testos#show
             PUT    /admin/testos/:id(.:format)      admin/testos#update
             DELETE /admin/testos/:id(.:format)      admin/testos#destroy

完整的TestosController:

class Admin::TestosController < ApplicationController
  # GET /testos
  # GET /testos.json
  def index
    @testos = Testo.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @testos }
    end
  end

  # GET /testos/1
  # GET /testos/1.json
  def show
    @testo = Testo.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @testo }
    end
  end

  # GET /testos/new
  # GET /testos/new.json
  def new
    @testo = Testo.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @testo }
    end
  end

  # GET /testos/1/edit
  def edit
    @testo = Testo.find(params[:id])
  end

  # POST /testos
  # POST /testos.json
  def create
    @testo = Testo.new(params[:testo])

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

  # PUT /testos/1
  # PUT /testos/1.json
  def update
    @testo = Testo.find(params[:id])

    respond_to do |format|
      if @testo.update_attributes(params[:testo])
        format.html { redirect_to @testo, notice: 'Testo was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @testo.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /testos/1
  # DELETE /testos/1.json
  def destroy
    @testo = Testo.find(params[:id])
    @testo.destroy

    respond_to do |format|
      format.html { redirect_to testos_url }
      format.json { head :no_content }
    end
  end
end

这是视图文件:

列出 testos

<table>
  <tr>
    <th>Title</th>
    <th>Entry</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @testos.each do |testo| %>
  <tr>
    <td><%= testo.title %></td>
    <td><%= testo.entry %></td>
    <td><%= link_to 'Show', testo %></td>
    <td><%= link_to 'Edit', edit_testo_path(testo) %></td>
    <td><%= link_to 'Destroy', testo, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New Testo', new_testo_path %>
4

1 回答 1

1

您的类声明应为:

class Admin::TestosController < ApplicationController
于 2013-05-31T15:26:50.770 回答