Newbie to RoR here. I have built models with no namespace. One of them is called 'Brand'. I then proceeded to use rails g "admin/brands" to put maintenance functionality under an admin namespace, using rails generate scaffolding_controller "admin/brand"
- which produced the views and the controller. The unit tests fail when I rake test:
NoMethodError: undefined method `admin_brands' for #<Admin::BrandsControllerTest:0x1034c0730>
test/functional/admin/brands_controller_test.rb:5:in `_callback_before_193'
in routes.rb I have:
# Administration routes
namespace :admin do
resources :brands
end
The generated controller code is as follows:
class Admin::BrandsController < ApplicationController
# GET /admin/brands
# GET /admin/brands.json
def index
@admin_brands = Brand.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @admin_brands }
end
end
# GET /admin/brands/1
# GET /admin/brands/1.json
def show
@admin_brand = Brand.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @admin_brand }
end
end
# GET /admin/brands/new
# GET /admin/brands/new.json
def new
@admin_brand = Brand.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @admin_brand }
end
end
# GET /admin/brands/1/edit
def edit
@admin_brand = Brand.find(params[:id])
end
# POST /admin/brands
# POST /admin/brands.json
def create
@admin_brand = Brand.new(params[:admin_brand])
respond_to do |format|
if @admin_brand.save
format.html { redirect_to @admin_brand, :notice => 'Brand was successfully created.' }
format.json { render :json => @admin_brand, :status => :created, :location => @admin_brand }
else
format.html { render :action => "new" }
format.json { render :json => @admin_brand.errors, :status => :unprocessable_entity }
end
end
end
# PUT /admin/brands/1
# PUT /admin/brands/1.json
def update
@admin_brand = Brand.find(params[:id])
respond_to do |format|
if @admin_brand.update_attributes(params[:admin_brand])
format.html { redirect_to @admin_brand, :notice => 'Brand was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @admin_brand.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /admin/brands/1
# DELETE /admin/brands/1.json
def destroy
@admin_brand = Brand.find(params[:id])
@admin_brand.destroy
respond_to do |format|
format.html { redirect_to admin_brands_url }
format.json { head :no_content }
end
end
end
Not sure how to debug this type of issue... I gather that paths are messed up somehow, but that is much as I can fathom at this point. Help appreciated.